Whitepaper - Ethereum Classic With Cover
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Ethereum</strong> <strong>Classic</strong> Documentation, Release 0.1<br />
2. Get the contract info json file.<br />
3. Deploy contract info json file to any url of your choice<br />
4. Register codehash ->content hash -> url<br />
The JS API makes this process very easy by providing helpers. Call admin.register to extract info from<br />
the contract, write out its json serialisation in the given file, calculates the content hash of the file and finally<br />
registers this content hash to the contract’s code hash. Once you deployed that file to any url, you can use<br />
admin.registerUrl to register the url with your content hash on the blockchain as well. (Note that in<br />
case a fixed content addressed model is used as document store, the url-hint is no longer necessary.)<br />
source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"<br />
// compile with solc<br />
contract = eth.compile.solidity(source).test<br />
// create contract object<br />
var MyContract = eth.contract(contract.info.abiDefinition)<br />
// extracts info from contract, save the json serialisation in the given file,<br />
contenthash = admin.saveInfo(contract.info, "~/dapps/shared/contracts/test/info.json")<br />
// send off the contract to the blockchain<br />
MyContract.new({from: primaryAccount, data: contract.code}, function(error, contract){<br />
if(!error && contract.address) {<br />
// calculates the content hash and registers it with the code hash in `HashReg`<br />
// it uses address to send the transaction.<br />
// returns the content hash that we use to register a url<br />
admin.register(primaryAccount, contract.address, contenthash)<br />
// here you deploy ~/dapps/shared/contracts/test/info.json to a url<br />
admin.registerUrl(primaryAccount, hash, url)<br />
}<br />
});<br />
Testing contracts and transactions<br />
Often you need to resort to a low level strategy of testing and debugging contracts and transactions. This section<br />
introduces some debug tools and practices you can use. In order to test contracts and transactions without realword<br />
consequences, you best test it on a private blockchain. This can be achieved with configuring an alternative<br />
network id (select a unique integer) and/or disable peers. It is recommended practice that for testing you use<br />
an alternative data directory and ports so that you never even accidentally clash with your live running node<br />
(assuming that runs using the defaults. Starting your geth with in VM debug mode with profiling and highest<br />
logging verbosity level is recommended:<br />
geth --datadir ~/dapps/testing/00/ --port 30310 --rpcport 8110 --networkid 4567890 --nodiscover --<br />
Before you can submit any transactions, you need set up your private test chain. See Test Networks.<br />
// create account. will prompt for password<br />
personal.newAccount();<br />
// name your primary account, will often use it<br />
primary = eth.accounts[0];<br />
// check your balance (denominated in ether)<br />
balance = web3.fromWei(eth.getBalance(primary), "ether");<br />
// assume an existing unlocked primary account<br />
primary = eth.accounts[0];<br />
// mine 10 blocks to generate ether<br />
// starting miner<br />
miner.start(4);<br />
// sleep for 10 blocks (this can take quite some time).<br />
admin.sleepBlocks(10);<br />
// then stop mining (just not to burn heat in vain)<br />
84 Chapter 1. Contents