geth --mine --datadir eth-data --networkid 123 --nodiscover --maxpeers 0 console 2>>geth.log
To verify that it's mining,
execute this command
to see the current block. Then wait 30 seconds and
execute it again.
eth.blockNumber
The block number should increase,
as shown below.
primary = eth.accounts[0]
personal.unlockAccount(primary)
Enter your password.
After a pause of several seconds, the
response is "true",
as shown below.
contract token {
mapping (address => uint) public coinBalanceOf;
event CoinTransfer(address sender, address receiver, uint amount);
/* Initializes contract with initial supply tokens to the creator of the contract */
function token(uint supply) {
coinBalanceOf[msg.sender] = supply;
}
/* Very simple trade function */
function sendCoin(address receiver, uint amount) returns(bool sufficient) {
if (coinBalanceOf[msg.sender] < amount) return false;
coinBalanceOf[msg.sender] -= amount;
coinBalanceOf[receiver] += amount;
CoinTransfer(msg.sender, receiver, amount);
return true;
}
}
var tokenSource = ' contract token { mapping (address => uint) public coinBalanceOf; event CoinTransfer(address sender, address receiver, uint amount); /* Initializes contract with initial supply tokens to the creator of the contract */ function token(uint supply) { coinBalanceOf[msg.sender] = supply; } /* Very simple trade function */ function sendCoin(address receiver, uint amount) returns(bool sufficient) { if (coinBalanceOf[msg.sender] < amount) return false; coinBalanceOf[msg.sender] -= amount; coinBalanceOf[receiver] += amount; CoinTransfer(msg.sender, receiver, amount); return true; } }'
Only the end of the code is visible, and the reply
is "undefined",
as shown below.
In the geth console, execute this command.
var tokenCompiled = eth.compile.solidity(tokenSource)
The reply
is "undefined" again,
as shown below.
var supply = 10000;
var tokenContract = web3.eth.contract(tokenCompiled.token.info.abiDefinition);
var token = tokenContract.new(
supply,
{
from:web3.eth.accounts[0],
data:tokenCompiled.token.code,
gas: 1000000
}, 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);
}
}
})
A "Contract transaction send" message appears,
and after a few seconds, you see
"Contract mined!",
as shown below. Make a note of your contract's "Address"
here--you will need it later.
token.coinBalanceOf(eth.accounts[0]) + " tokens"
You have 10000 tokens,
as shown below.
In the geth console, execute this command.
var event = token.CoinTransfer({}, '', function(error, result){
if (!error)
console.log("Coin transfer: " + result.args.amount + " tokens were sent. Balances now are as following: \n Sender:\t" + result.args.sender + " \t" + token.coinBalanceOf.call(result.args.sender) + " tokens \n Receiver:\t" + result.args.receiver + " \t" + token.coinBalanceOf.call(result.args.receiver) + " tokens" )
});
The reply is "undefined",
as shown below.
personal.newAccount()
Enter a password twice. Your new account's
address appears, as shown below.
personal.listAccounts
You now have two accounts,
as shown below.
In the geth console, execute this command.
token.coinBalanceOf(eth.accounts[0]) + " tokens"
The transaction succeeds and returns a transaction
ID. Then the Watcher prints out the new balances
in both accounts,
as shown below.