Skip to content

Instantly share code, notes, and snippets.

@zelig
Created May 4, 2015 21:08
Show Gist options
  • Save zelig/21ac8eada617e56866d8 to your computer and use it in GitHub Desktop.
Save zelig/21ac8eada617e56866d8 to your computer and use it in GitHub Desktop.
advancing blockchain on a private test network
// assume an existing unlocked primary account
primary = eth.accounts[0];
// mine 10 blocks to generate ether
admin.miner.start();
admin.debug.waitForBlocks(eth.blockNumber+10);
admin.miner.stop() ;
balance = web3.fromWei(eth.getBalance(primary), "ether");
admin.contractInfo.newRegistry(primary);
source = "contract test {\n" +
" /// @notice will multiply `a` by 7.\n" +
" function multiply(uint a) returns(uint d) {\n" +
" return a * 7;\n" +
" }\n" +
"} ";
contract = eth.compile.solidity(source);
contractaddress = eth.sendTransaction({from: primary, data: contract.code});
eth.getBlock("pending", true).transactions;
// wait for the next block
// should use filters here and/or
// unfortunately this might crash the miner if blocks are found quickly
admin.miner.start()
// waits until block height is minimum the number given.
// basically a sleep function on variable block units of time.
admin.debug.waitForBlocks(eth.blockNumber+1);
admin.miner.stop()
code = eth.getCode(contractaddress);
abiDef = JSON.parse('[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}]');
Multiply7 = eth.contract(abiDef);
multiply7 = new Multiply7(contractaddress);
fortytwo = multiply7.multiply.call(6);
console.log("multiply7.multiply.call(6) => "+fortytwo);
multiply7.multiply.sendTransaction(6, {from: primary})
admin.miner.start();
admin.debug.waitForBlocks(eth.blockNumber+2);
admin.miner.stop();
filename = "/tmp/info.json";
contenthash = admin.contractInfo.register(primary, contractaddress, contract, filename);
admin.contractInfo.registerUrl(primary, contenthash, "file://"+filename);
admin.miner.start();
admin.debug.waitForBlocks(eth.blockNumber+2);
admin.miner.stop();
info = admin.contractInfo.get(contractaddress);
admin.contractInfo.start();
abiDef = JSON.parse('[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}]');
Multiply7 = eth.contract(abiDef);
multiply7 = new Multiply7(contractaddress);
fortytwo = multiply7.multiply.sendTransaction(6, { from: primary });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment