Here's a step-by-step guide of deploying and running Greeter on Testnet.
I you do not already have a coinbase account, run the following command:
user@Kumquat:~$ geth --testnet account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat Passphrase:
Address: {730b87e78b07fb2bf1b1e8b127b3353d08d72706}
Then start geth --testnet
on the Testnet with the --mine --minerthreads 1 --unlock 0
parameter with the console
command. You will have to enter in your password to unlock the account:
user@Kumquat:~$ geth --testnet --mine --minerthreads 1 --unlock 0 console
...
Unlocking account 0 | Attempt 1/3
Passphrase:
> I0615 01:37:11.434270 ethash.go:291] Generating DAG: 0%
I0615 01:37:19.280918 ethash.go:291] Generating DAG: 1%
...
I0615 01:40:09.629009 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 120 txs in 2.822940573s. #1039346 [534c4f03 / c9f46493]
I0615 01:40:09.723141 ethash.go:291] Generating DAG: 17%
...
I0615 01:59:43.271478 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 366 txs in 6.860619737s. #1113842 [cb034c71 / 909241a8]
I0615 01:59:48.964948 ethash.go:291] Generating DAG: 100%
I0615 01:59:48.969898 ethash.go:276] Done generating DAG for epoch 34, it took 22m39.495183713s
I0615 01:59:50.226735 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 401 txs in 6.953559841s. #1114098 [2f30678a / aa5b5fd1]
The DAG has now been created and but the blockchain is still being downloaded - from the imported 256 block(s)
message above.
Note that you don't have to mine the Testnet blockchain, as another miner (if there is one) will pick up your transaction and include your transaction in a mined block.
You can check the syncing status using the following command:
> eth.syncing
{
currentBlock: 1123788,
highestBlock: 1133372,
knownStates: 0,
pulledStates: 0,
startingBlock: 1024655
}
> I0615 02:02:03.312407 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 306 txs in 8.307949518s. #1123826 [e9d853f5 / a549429b]
The blockchain has now finished syncing. Let's check the mining status and our coinbase account:
I0615 02:09:36.554320 miner/worker.go:555] commit new work on block 1133511 with 0 txs & 0 uncles. Took 293.439µs
I0615 02:09:38.061406 core/blockchain.go:959] imported 1 block(s) (0 queued 0 ignored) including 0 txs in 8.141851ms. #1133511 [140a530f / 140a530f]
I0615 02:09:38.061848 miner/worker.go:555] commit new work on block 1133512 with 0 txs & 0 uncles. Took 210.852µs
> eth.mining
true
> web3.fromWei(eth.getBalance(eth.accounts[0]).toNumber(), "ether")
"28.902244797526348"
In a separate window, run top
from your command line and you should see geth
utilising 100+% CPU
I'm using the source code listed in Deploying the Greeter contract via the geth CLI is not registering in my private blockchain.
> var greeterSource = 'contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }'
undefined
> var greeterCompiled = web3.eth.compile.solidity(greeterSource)
I0615 02:16:00.290143 common/compiler/solidity.go:114] solc, the solidity compiler commandline interface
Version: 0.3.4-0/RelWithDebInfo-Linux/g++/Interpreter
path: /usr/bin/solc
undefined
Let's check the compiled information:
> greeterCompiled
{
greeter: {
code: "0x606060405260405161023e38038061023e8339810160405280510160008054600160a060020a031916331790558060016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10609f57805160ff19168380011785555b50608e9291505b8082111560cc57600081558301607d565b50505061016e806100d06000396000f35b828001600101855582156076579182015b82811115607657825182600050559160200191906001019060b0565b509056606060405260e060020a600035046341c0e1b58114610026578063cfae321714610068575b005b6100246000543373ffffffffffffffffffffffffffffffffffffffff908116911614156101375760005473ffffffffffffffffffffffffffffffffffffffff16ff5b6100c9600060609081526001805460a06020601f6002600019610100868816150201909416939093049283018190040281016040526080828152929190828280156101645780601f1061013957610100808354040283529160200191610164565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101295780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b565b820191906000526020600020905b81548152906001019060200180831161014757829003601f168201915b505050505090509056",
info: {
abiDefinition: [{...}, {...}, {...}],
compilerOptions: "--bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc736903870",
compilerVersion: "0.3.4",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.3.4",
source: "contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }",
userDoc: {
methods: {}
}
}
},
mortal: {
code: "0x606060405260008054600160a060020a03191633179055605c8060226000396000f3606060405260e060020a600035046341c0e1b58114601a575b005b60186000543373ffffffffffffffffffffffffffffffffffffffff90811691161415605a5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b56",
info: {
abiDefinition: [{...}, {...}],
compilerOptions: "--bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc736903870",
compilerVersion: "0.3.4",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.3.4",
source: "contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }",
userDoc: {
methods: {}
}
}
}
}
Send the transaction to insert the contract code into the blockchain. You will see that the contract transaction has been successfully mined.
> var _greeting = "Hello World!"
undefined
> var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);
undefined
> var greeter = greeterContract.new(_greeting, {from: eth.accounts[0], data: greeterCompiled.greeter.code, gas: 4000000},
function(e, contract) {
if (!e) {
if (!contract.address) {
console.log("Contract transaction send: TransactionHash: " +
contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
})
Contract transaction send: TransactionHash: 0xcad6fb4afbf49a77fbd5622435ae010d0665b54f9eda18ad50858effe98f23f5 waiting to be mined...
undefined
Contract mined! Address: 0x170ab13569f1c8c9f99918b7f220ce88d1bc4beb
[object Object]
We can now call the greet()
function:
> greeter.greet();
"Hello World!"