安裝Go-ethereum (geth)
使用cmd創建資料夾並移動到該目錄
在該目錄下新增檔案genesis.json
{
"config": {
"chainId": 123456,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000042",
"difficulty": "0x020000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x4c4b40",
"alloc": {}
}
//初始化並建立一個新的節點
geth --datadir data init genesis.json
//啟動節點
geth --datadir data --networkid 123456 --rpc --rpccorsdomain "*" console
//建立帳戶
personal.newAccount()
//開始挖礦
miner.start()
//停止挖礦
miner.stop()
//查看帳戶[0]餘額
eth.getBalance(eth.accounts[0])
(置頂圖)使用Remix - Solidity IDE撰寫智慧合約!
- environment選擇Web3 Provider(連接到自身node)
- 帳戶有餘額才能使用
//解鎖帳戶
personal.unlockAccount(eth.accounts[0])
//按 Create(cmd產生的contract待會用到)
//查看Detail內的ABI並複製
/*我的複製不能用,求解 ( ′????ω????` )
只好自己透過上面的資訊自行編輯
用成以下格式宣告於cmd中*/
var abi = [{"constant": false, "inputs": [{"name": "numCandidate", "type": "uint256"}], "name": "voteCandidate", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "getResult", "outputs": [{"name":"", "type":"string"}, {"name":"", "type":"uint256"}, {"name":"", "type":"string"}, {"name":"", "type":"uint256"}], "payable": false, "stateMutability": "view", "type": "function"}]
//將上方產生的contract宣告於此,記得雙引號 " "。
var address = "0x44141F94a85C08cF14ac05f8b0483e5613a65B60"
//定義vote合約
var vote = eth.contract(abi).at(address)
//定義defaultAccount
eth.defaultAccount = eth.accounts[0]
//投票(1號或2號)
vote.voteCandidate(1)
//要先讓他挖一下才會有結果
miner.start()
//停止探勘
miner.stop()
//查看投票結果
vote.getResult()