genesis.json
chaindId:區塊鏈的識別 ID。
difiiculty:難度參數。
coinbase:預設將會是你第一個建立帳號的礦工。
gasLimit:交易所使用到的 gas 限制。
geth --datadir data init genesis.json
–-datadir:區塊會儲存在 data 資料夾中。 init:初始參數所使用的配置檔案 genesis.json
也可使用puppeth建立
geth -syncmode fast --cache=1024 --datadir data --networkid 123456 --rpc --rpccorsdomain "*" --nodiscover --rpcapi="db,eth,net,web3,personal" console
--networkid:設定鏈的 ID。
--rpc:啟動 rpc 通訊協定功能,如果要佈署「智慧合約」,請務必加入。
--rpccorsdomain:允許跨網域的存取調用,「"*"」 代表來自任何網段。
--nodiscover:不搜尋其他網段上的節點。
--rpcapi:在 rpc 通訊中,提供合約 API 的服務項目。
console:將會啟動命令模式
--cache=1024: (1G)
--ipcdisable: 禁用IPC-RPC服務器
geth attach ipc:data/geth.ipc
geth attach http://localhost:8545
admin.nodeInfo
personal.newAccount()
eth.accounts
eth.getBalance(eth.accounts[0])
eth.coinbase
設當前礦工帳號為預設帳號
miner.setEtherbase(eth.accounts[0])
在每一次交易的時候,都需要解鎖帳號。
personal.unlockAccount(eth.accounts[0])
eth.blockNumber
eth.getBlock(0)
eth.getTransaction("0x0....")
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(3,"ether")})
from:來源帳號地址,可以使用 eth.accounts 指令查詢,或是直接帶入帳號地址。 to:交易對象,即為對方的地址。 value:交易內容,其中 3 為交易金額,ether 為貨幣單位。
txpool.status
miner.start(1)
參數為 CPU 使用數
miner.stop()