创建创世区块
| 1 | mkdir one | 
genesis.json的内容如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17{
  "config": {
        "chainId": 10, 
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
  },  
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "", 
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00",
  "alloc"      : { } 
}
创建区块链和基本操作
| 1 | geth init ./genesis.json --datadir "./chain" | 
挖矿1
2
3
4
5miner.start(1)
miner.stop()
web3.eth.getBalance(web3.eth.accounts[0])
web3.eth.getBalance(web3.eth.accounts[1])
web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0])
函数1
2
3
4
5
6
7
8
9
10
11function checkAllBalances() {
     var totalBal = 0;
     for (var acctNum in eth.accounts) {
         var acct = eth.accounts[acctNum];
         var acctBal = web3.fromWei(eth.getBalance(acct), "ether");
         totalBal += parseFloat(acctBal);
         console.log("  eth.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " ether");
     }
     console.log("  Total balance: " + totalBal + " ether");
 };
checkAllBalances()
转账1
2
3
4
5
6
7
8acc0 = web3.eth.accounts[0]
acc1 = web3.eth.accounts[1]
web3.personal.unlockAccount(acc0,"123456")
web3.eth.sendTransaction({from:acc0,to:acc1,value:web3.toWei(3,"ether")})
checkAllBalances()
miner.start()
checkAllBalances()
web3.eth.blockNumber
 
        