鏈客,專爲開發者而生,有問必答!node
此文章來自區塊鏈技術社區,未經容許拒絕轉載。
linux
目錄git
2.1. Ubuntu
2.1.1. 安裝 geth
2.1.2. 安裝 solc
2.2. Windows
2.3. Mac OS
2.4. 編譯安裝github
3.1. 初始化創世區塊
3.2. 啓動節點
3.2.1. rpcaddr
3.3. 使用節點進行挖礦
3.3.1. 啓動礦工開始挖礦
3.3.2. 中止挖礦
3.3.3. 查看所挖金額golang
4.1. 控制檯
4.2. 鏈接控制檯
4.3. 帳號管理
4.3.1. 新建帳號
4.3.2. 查看帳號
4.4. 運行JSweb
5.1. personal 管理
5.1.1. 建立帳號
5.1.2. 顯示帳號
5.2. eth 管理
5.2.1. 礦工帳號
5.2.2. 餘額
5.2.2.1. 單位轉換
5.2.3. 轉帳
5.3. admin 管理
5.3.1. 顯示節點
5.3.2. 查看池
5.3.3. 添加節點
5.4. miner 挖礦管理
5.4.1. 開始挖礦
5.4.2. 中止挖礦數據庫
7.1. Error: authentication needed: password or unlockjson
區塊鏈是什麼?一句話,它是一種特殊的(非關係型)分佈式數據庫,這種數據庫只能作插入和查找操做,而且沒有管理員。api
首先,區塊鏈的主要做用是儲存信息。任何須要保存的信息,均可以寫入區塊鏈,也能夠從裏面讀取,因此它是數據庫。服務器
其次,任何人均可以架設服務器,加入區塊鏈網絡,成爲一個節點。區塊鏈的世界裏面,沒有中心節點,每一個節點都是平等的,都保存着整個數據庫。你能夠向任何一個節點,寫入/讀取數據,由於全部節點最後都會同步,保證區塊鏈一致。
2.1. Ubuntu
2.1.1. 安裝 geth
安裝環境
Ubuntu 17.10
sudo apt upgrade -y
sudo apt install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt update
sudo apt install ethereum
neo@netkiller ~ % geth version
Geth
Version: 1.7.3-stable
Git Commit: 4bb3c89d44e372e6a9ab85a8be0c9345265c763a
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.1
Operating System: linux
GOPATH=
GOROOT=/usr/lib/go-1.9
2.1.2. 安裝 solc
sudo apt install solc -y
neo@netkiller ~ % solc --version
solc, the solidity compiler commandline interface
Version: 0.4.19+commit.c4cbbb05.Linux.g++
2.2. Windows
訪問 https://geth.ethereum.org/dow...
下載並安裝 Geth for Windows
2.3. Mac OS
brew tap ethereum/ethereum
brew install ethereum
2.4. 編譯安裝
git clone https://github.com/ethereum/g...
sudo apt-get install -y build-essential golang
cd go-ethereum
make geth
cd ~
mkdir -p ethereum
cd ethereum
3.1. 初始化創世區塊
建立文件 genesis.json
{
"nonce": "0x0000000000000042",
"difficulty": "0x020000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x4c4b40",
"config": {
"chainId": 15, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0
},
"alloc": { }
}
mixhash: 與nonce配合用於挖礦,由上一個區塊的一部分生成的hash。注意他和nonce的設置須要知足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章節所描述的條件。.
nonce: nonce就是一個64位隨機數,用於挖礦,注意他和mixhash的設置須要知足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章節所描述的條件。
difficulty: 設置當前區塊的難度,若是難度過大,cpu挖礦就很難,這裏設置較小難度
alloc: 用來預置帳號以及帳號的以太幣數量,由於私有鏈挖礦比較容易,因此咱們不須要預置有幣的帳號,須要的時候本身建立便可以。
coinbase: 礦工的帳號,隨便填
timestamp: 設置創世塊的時間戳
parentHash: 上一個區塊的hash值,由於是創世塊,因此這個值是0
extraData: 附加信息,隨便填,能夠填你的個性信息
gasLimit: 該值設置對GAS的消耗總量限制,用來限制區塊能包含的交易信息總和,由於咱們是私有鏈,因此填最大。
初始化創世區塊
neo@netkiller ~/ethereum % geth init genesis.json
WARN [01-19|17:35:17] No etherbase set and no accounts found as default
INFO [01-19|17:35:17] Allocated cache and file handles database=/home/neo/.ethereum/geth/chaindata cache=16 handles=16
INFO [01-19|17:35:17] Writing custom genesis block
INFO [01-19|17:35:17] Successfully wrote genesis state database=chaindata hash=611596…424d04
INFO [01-19|17:35:17] Allocated cache and file handles database=/home/neo/.ethereum/geth/lightchaindata cache=16 handles=16
INFO [01-19|17:35:18] Writing custom genesis block
INFO [01-19|17:35:18] Successfully wrote genesis state database=lightchaindata hash=611596…424d04
默認目錄是 /home/neo/.ethereum/ 你能夠經過 --datadir 參數指定目錄
neo@netkiller ~/ethereum % geth --datadir data init genesis.json
WARN [01-19|17:38:16] No etherbase set and no accounts found as default
INFO [01-19|17:38:16] Allocated cache and file handles database=/home/neo/ethereum/data/geth/chaindata cache=16 handles=16
INFO [01-19|17:38:17] Writing custom genesis block
INFO [01-19|17:38:17] Successfully wrote genesis state database=chaindata hash=611596…424d04
INFO [01-19|17:38:17] Allocated cache and file handles database=/home/neo/ethereum/data/geth/lightchaindata cache=16 handles=16
INFO [01-19|17:38:17] Writing custom genesis block
INFO [01-19|17:38:17] Successfully wrote genesis state database=lightchaindata hash=611596…424d04
neo@netkiller ~/ethereum % find data
data
data/keystore
data/geth
data/geth/chaindata
data/geth/chaindata/LOCK
data/geth/chaindata/LOG
data/geth/chaindata/MANIFEST-000000
data/geth/chaindata/CURRENT
data/geth/chaindata/000001.log
data/geth/lightchaindata
data/geth/lightchaindata/LOCK
data/geth/lightchaindata/LOG
data/geth/lightchaindata/MANIFEST-000000
data/geth/lightchaindata/CURRENT
data/geth/lightchaindata/000001.log
目錄結構
data
├── geth
│ ├── chaindata
│ │ ├── 000001.log
│ │ ├── CURRENT
│ │ ├── LOCK
│ │ ├── LOG
│ │ └── MANIFEST-000000
│ └── lightchaindata
│ ├── 000001.log
│ ├── CURRENT
│ ├── LOCK
│ ├── LOG
│ └── MANIFEST-000000
└── keystore
3.2. 啓動節點
neo@netkiller ~/ethereum % geth --networkid 123456 --rpc --rpccorsdomain "*" --nodiscover console
WARN [01-19|17:47:06] No etherbase set and no accounts found as default
INFO [01-19|17:47:06] Starting peer-to-peer node instance=Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
INFO [01-19|17:47:06] Allocated cache and file handles database=/home/neo/.ethereum/geth/chaindata cache=128 handles=1024
INFO [01-19|17:47:06] Initialised chain configuration config="{ChainID: 15 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Engine: unknown}"
INFO [01-19|17:47:06] Disk storage enabled for ethash caches dir=/home/neo/.ethereum/geth/ethash count=3
INFO [01-19|17:47:06] Disk storage enabled for ethash DAGs dir=/home/neo/.ethash count=2
INFO [01-19|17:47:06] Initialising Ethereum protocol versions="[63 62]" network=123456
INFO [01-19|17:47:06] Loaded most recent local header number=0 hash=611596…424d04 td=131072
INFO [01-19|17:47:06] Loaded most recent local full block number=0 hash=611596…424d04 td=131072
INFO [01-19|17:47:06] Loaded most recent local fast block number=0 hash=611596…424d04 td=131072
INFO [01-19|17:47:06] Loaded local transaction journal transactions=0 dropped=0
INFO [01-19|17:47:06] Regenerated local transaction journal transactions=0 accounts=0
INFO [01-19|17:47:06] Starting P2P networking
INFO [01-19|17:47:06] RLPx listener up self="enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@[::]:30303?discport=0"
INFO [01-19|17:47:06] IPC endpoint opened: /home/neo/.ethereum/geth.ipc
INFO [01-19|17:47:06] HTTP endpoint opened: http://127.0.0.1:8545
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
INFO [01-19|17:47:09] Mapped network port proto=tcp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"
identity: 區塊鏈的標示,隨便填寫,用於標示目前網絡的名字
init: 指定創世塊文件的位置,並建立初始塊
datadir: 設置當前區塊鏈網絡數據存放的位置
port: 網絡監聽端口
rpc: 啓動rpc通訊,能夠進行智能合約的部署和調試
rpcapi: 設置容許鏈接的rpc的客戶端,通常爲db,eth,net,web3
networkid: 設置當前區塊鏈的網絡ID,用於區分不一樣的網絡,是一個數字
console: 啓動命令行模式,能夠在Geth中執行命令
3.2.1. rpcaddr
默認是 127.0.0.1
HTTP endpoint closed: http://127.0.0.1:8545
經過 --rpcaddr="0.0.0.0" 指定監聽地址
HTTP endpoint opened: http://0.0.0.0:8545
neo@netkiller ~/ethereum % geth --networkid 123456 --rpc --rpcaddr="0.0.0.0" --rpccorsdomain "*" --nodiscover console
INFO [01-20|01:41:33] Starting peer-to-peer node instance=Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
INFO [01-20|01:41:33] Allocated cache and file handles database=/home/neo/.ethereum/geth/chaindata cache=128 handles=1024
INFO [01-20|01:41:34] Initialised chain configuration config="{ChainID: 15 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Engine: unknown}"
INFO [01-20|01:41:34] Disk storage enabled for ethash caches dir=/home/neo/.ethereum/geth/ethash count=3
INFO [01-20|01:41:34] Disk storage enabled for ethash DAGs dir=/home/neo/.ethash count=2
INFO [01-20|01:41:34] Initialising Ethereum protocol versions="[63 62]" network=123456
INFO [01-20|01:41:34] Loaded most recent local header number=531 hash=1a2707…3a27bc td=79083846
INFO [01-20|01:41:34] Loaded most recent local full block number=531 hash=1a2707…3a27bc td=79083846
INFO [01-20|01:41:34] Loaded most recent local fast block number=531 hash=1a2707…3a27bc td=79083846
INFO [01-20|01:41:34] Loaded local transaction journal transactions=0 dropped=0
INFO [01-20|01:41:34] Regenerated local transaction journal transactions=0 accounts=0
WARN [01-20|01:41:34] Blockchain not empty, fast sync disabled
INFO [01-20|01:41:34] Starting P2P networking
INFO [01-20|01:41:34] RLPx listener up self="enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@[::]:30303?discport=0"
INFO [01-20|01:41:34] IPC endpoint opened: /home/neo/.ethereum/geth.ipc
INFO [01-20|01:41:34] HTTP endpoint opened: http://0.0.0.0:8545
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
coinbase: 0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6
at block: 531 (Tue, 14 Nov 2017 17:36:05 HST)
datadir: /home/neo/.ethereum
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
INFO [01-20|01:41:40] Mapped network port proto=tcp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"
3.3. 使用節點進行挖礦
3.3.1. 啓動礦工開始挖礦
miner.start(1)
這裏的1表示只使用一個線程運行,第一次運行時將開始建立DAG文件,只需等待進度條到100,則將開始挖礦。 實際你看到的挖礦速度很快,這是由於咱們已經在初始化創世區塊時配置爲:"nonce": "0x0000000000000042"。 「0x42」難度能讓你在私有測試網鏈上快速挖以太幣。
提示
挖礦時必然有礦工帳戶,而系統默認使用建立的第一個帳號。
miner.start(1)
INFO [01-19|21:06:43] Updated mining threads threads=1
INFO [01-19|21:06:43] Transaction pool price threshold updated price=18000000000
INFO [01-19|21:06:43] Starting mining operation
null
INFO [01-19|21:06:43] Commit new mining work number=1 txs=0 uncles=0 elapsed=717.552µs
INFO [01-19|21:06:46] Generating ethash verification cache epoch=0 percentage=91 elapsed=3.000s
INFO [01-19|21:06:46] Generated ethash verification cache epoch=0 elapsed=3.273s
INFO [01-19|21:06:51] Generating DAG in progress epoch=0 percentage=0 elapsed=5.056s
INFO [01-19|21:06:56] Generating DAG in progress epoch=0 percentage=1 elapsed=10.140s
INFO [01-19|21:07:01] Generating DAG in progress epoch=0 percentage=2 elapsed=15.119s
INFO [01-19|21:07:06] Generating DAG in progress epoch=0 percentage=3 elapsed=19.924s
INFO [01-19|21:07:11] Generating DAG in progress epoch=0 percentage=4 elapsed=24.739s
INFO [01-19|21:07:16] Generating DAG in progress epoch=0 percentage=5 elapsed=29.473s
INFO [01-19|21:07:22] Generating DAG in progress epoch=0 percentage=6 elapsed=35.641s
INFO [01-19|21:07:26] Generating DAG in progress epoch=0 percentage=7 elapsed=40.374s
INFO [01-19|21:07:31] Generating DAG in progress epoch=0 percentage=8 elapsed=45.134s
INFO [01-19|21:07:36] Generating DAG in progress epoch=0 percentage=9 elapsed=49.908s
INFO [01-19|21:07:41] Generating DAG in progress epoch=0 percentage=10 elapsed=54.633s
......
......
......
INFO [01-19|21:22:43] Generated ethash verification cache epoch=0 elapsed=15m57.328s
INFO [01-19|21:22:47] Generating ethash verification cache epoch=1 percentage=17 elapsed=3.031s
INFO [01-19|21:22:50] Generating ethash verification cache epoch=1 percentage=34 elapsed=6.056s
INFO [01-19|21:22:53] Generating ethash verification cache epoch=1 percentage=49 elapsed=9.562s
INFO [01-19|21:22:57] Generating ethash verification cache epoch=1 percentage=70 elapsed=13.115s
INFO [01-19|21:23:00] Generating ethash verification cache epoch=1 percentage=90 elapsed=16.123s
INFO [01-19|21:23:01] Generated ethash verification cache epoch=1 elapsed=17.576s
INFO [01-19|21:23:19] Generating DAG in progress epoch=1 percentage=0 elapsed=18.198s
INFO [01-19|21:23:32] Successfully sealed new block number=1 hash=e2b5b9…9b1bfe
INFO [01-19|21:23:32] 🔨 mined potential block number=1 hash=e2b5b9…9b1bfe
INFO [01-19|21:23:32] Commit new mining work number=2 txs=0 uncles=0 elapsed=1.188ms
INFO [01-19|21:23:37] Generating DAG in progress epoch=1 percentage=1 elapsed=35.913s
INFO [01-19|21:23:41] Successfully sealed new block number=2 hash=62db3f…e27b50
INFO [01-19|21:23:41] 🔨 mined potential block number=2 hash=62db3f…e27b50
INFO [01-19|21:23:41] Commit new mining work number=3 txs=0 uncles=0 elapsed=772.239µs
INFO [01-19|21:23:43] Successfully sealed new block number=3 hash=34384b…c387f2
INFO [01-19|21:23:43] 🔨 mined potential block number=3 hash=34384b…c387f2
INFO [01-19|21:23:43] Commit new mining work number=4 txs=0 uncles=0 elapsed=1.002ms
INFO [01-19|21:23:55] Generating DAG in progress epoch=1 percentage=2 elapsed=53.757s
INFO [01-19|21:24:13] Generating DAG in progress epoch=1 percentage=3 elapsed=1m11.561s
INFO [01-19|21:24:30] Generating DAG in progress epoch=1 percentage=4 elapsed=1m28.986s
INFO [01-19|21:24:30] Successfully sealed new block number=4 hash=681970…462135
INFO [01-19|21:24:30] 🔨 mined potential block number=4 hash=681970…462135
INFO [01-19|21:24:30] Commit new mining work number=5 txs=0 uncles=0 elapsed=833.629µs
INFO [01-19|21:24:36] Successfully sealed new block number=5 hash=7b058b…d2f07a
INFO [01-19|21:24:36] 🔨 mined potential block number=5 hash=7b058b…d2f07a
INFO [01-19|21:24:36] Commit new mining work number=6 txs=0 uncles=0 elapsed=897.815µs
INFO [01-19|21:24:43] Successfully sealed new block number=6 hash=a5fc3d…b1221e
INFO [01-19|21:24:43] 🔗 block reached canonical chain number=1 hash=e2b5b9…9b1bfe
INFO [01-19|21:24:43] 🔨 mined potential block number=6 hash=a5fc3d…b1221e
INFO [01-19|21:24:43] Commit new mining work number=7 txs=0 uncles=0 elapsed=758.061µs
INFO [01-19|21:24:47] Successfully sealed new block number=7 hash=003b02…e886fd
INFO [01-19|21:24:47] 🔗 block reached canonical chain number=2 hash=62db3f…e27b50
INFO [01-19|21:24:47] 🔨 mined potential block number=7 hash=003b02…e886fd
INFO [01-19|21:24:47] Commit new mining work number=8 txs=0 uncles=0 elapsed=920.862µs
INFO [01-19|21:24:48] Generating DAG in progress epoch=1 percentage=5 elapsed=1m46.827s
INFO [01-19|21:25:06] Generating DAG in progress epoch=1 percentage=6 elapsed=2m4.338s
INFO [01-19|21:25:23] Successfully sealed new block number=8 hash=fd23c9…361c65
INFO [01-19|21:25:23] 🔗 block reached canonical chain number=3 hash=34384b…c387f2
INFO [01-19|21:25:23] 🔨 mined potential block number=8 hash=fd23c9…361c65
INFO [01-19|21:25:23] Commit new mining work number=9 txs=0 uncles=0 elapsed=825.737µs
INFO [01-19|21:25:23] Generating DAG in progress epoch=1 percentage=7 elapsed=2m22.061s
3.3.2. 中止挖礦
miner.stop()
true3.3.3. 查看所挖金額
eth.getBalance(eth.accounts[0])
70000000000000000000
4.1. 控制檯
neo@netkiller ~/ethereum % geth --networkid 123456 console
INFO [01-19|22:14:52] Starting peer-to-peer node instance=Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
INFO [01-19|22:14:52] Allocated cache and file handles database=/home/neo/.ethereum/geth/chaindata cache=128 handles=1024
INFO [01-19|22:14:52] Initialised chain configuration config="{ChainID: 15 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Engine: unknown}"
INFO [01-19|22:14:52] Disk storage enabled for ethash caches dir=/home/neo/.ethereum/geth/ethash count=3
INFO [01-19|22:14:52] Disk storage enabled for ethash DAGs dir=/home/neo/.ethash count=2
INFO [01-19|22:14:52] Initialising Ethereum protocol versions="[63 62]" network=123456
INFO [01-19|22:14:52] Loaded most recent local header number=14 hash=70d7f1…45850a td=1966848
INFO [01-19|22:14:52] Loaded most recent local full block number=14 hash=70d7f1…45850a td=1966848
INFO [01-19|22:14:52] Loaded most recent local fast block number=14 hash=70d7f1…45850a td=1966848
INFO [01-19|22:14:52] Loaded local transaction journal transactions=0 dropped=0
INFO [01-19|22:14:52] Regenerated local transaction journal transactions=0 accounts=0
WARN [01-19|22:14:52] Blockchain not empty, fast sync disabled
INFO [01-19|22:14:52] Starting P2P networking
INFO [01-19|22:14:56] UDP listener up self=enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@101.232.64.12:30303
INFO [01-19|22:14:56] RLPx listener up self=enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@101.232.64.12:30303
INFO [01-19|22:14:56] IPC endpoint opened: /home/neo/.ethereum/geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
coinbase: 0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6
at block: 14 (Fri, 19 Jan 2018 21:27:16 HST)
datadir: /home/neo/.ethereum
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
INFO [01-19|22:14:56] Mapped network port proto=udp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"
4.2. 鏈接控制檯
通常測試啓動咱們使用 console,若是是正式啓動無需使用 console。同事咱們使用&符號使其進入後臺運行。
neo@netkiller ~/ethereum % geth --networkid 123456 --rpc --rpcaddr="0.0.0.0" --rpccorsdomain "*" --nodiscover &
進入控制檯
neo@netkiller ~/ethereum % geth attach
Welcome to the Geth JavaScript console!
instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1
coinbase: 0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6
at block: 531 (Tue, 14 Nov 2017 17:36:05 HST)
datadir: /home/neo/.ethereum
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
退出控制檯
exit
鏈接遠程控制檯
neo@netkiller ~/ethereum % geth --exec 'eth.coinbase' attach http://172.16.0.10:8545
"0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6"
4.3. 帳號管理
4.3.1. 新建帳號
查看帳號
neo@netkiller ~/ethereum % geth account list
Account #0: {83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6} keystore:///home/neo/.ethereum/keystore/UTC--2018-01-20T04-04-06.786586541Z--83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6
建立帳號
neo@netkiller ~/ethereum % geth account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {e8abf98484325fd6afc59b804ac15804b978e607}
指定密碼
echo "abc123" > passwd
geth -password passwd account new
4.3.2. 查看帳號
neo@netkiller ~/ethereum % geth account list
Account #0: {83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6} keystore:///home/neo/.ethereum/keystore/UTC--2018-01-20T04-04-06.786586541Z--83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6
Account #1: {e8abf98484325fd6afc59b804ac15804b978e607} keystore:///home/neo/.ethereum/keystore/UTC--2018-01-20T06-11-23.608902164Z--e8abf98484325fd6afc59b804ac15804b978e607
4.4. 運行JS
neo@netkiller ~/ethereum % geth --exec "eth.blockNumber" attach
531
$ geth --exec 'loadScript("/tmp/checkbalances.js")' attach http://123.123.123.123:8545
$ geth --jspath "/tmp" --exec 'loadScript("checkbalances.js")' attach http://123.123.123.123:8545
5.1. personal 管理
5.1.1. 建立帳號
personal.newAccount()
Passphrase:
Repeat passphrase:
"0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6"
5.1.2. 顯示帳號
列出全部帳號personal.listAccounts
["0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6", "0xe8abf98484325fd6afc59b804ac15804b978e607"]
列出指定帳號personal.listAccounts[1]
"0xe8abf98484325fd6afc59b804ac15804b978e607"personal.listAccounts[0]
"0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6"
5.2. eth 管理
5.2.1. 礦工帳號
查看默認曠工帳號,系統中的第一個帳號。eth.coinbase
"0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6"
查看帳號列表eth.accounts
["0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6", "0xe8abf98484325fd6afc59b804ac15804b978e607"]eth.accounts[0]
"0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6"
5.2.2. 餘額
eth.getBalance(eth.accounts[0])
70000000000000000000
5.2.2.1. 單位轉換
eth.getBalance()返回的餘額是以太幣的最小面額wei,將wei轉換爲以太幣ether。
primary = eth.accounts[0]
balance = web3.fromWei(eth.getBalance(primary), "ether");
演示
primary = eth.accounts[0]
"0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6"
balance = web3.fromWei(eth.getBalance(primary), "ether");
70
5.2.3. 轉帳
personal.unlockAccount("0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6", "", 300)
eth.sendTransaction({from: '0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6', to: '0xe8abf98484325fd6afc59b804ac15804b978e607', value: web3.toWei(1, "ether")})
默認礦工帳號eth.coinbase
"0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6"
查看系統中的帳號,若是沒有請參考上面章節建立
eth.accounts
["0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6", "0xe8abf98484325fd6afc59b804ac15804b978e607"]
轉出帳號中又 285 個以太幣
web3.fromWei(eth.getBalance(eth.accounts[0]))
285
轉入帳號目前是 0
web3.fromWei(eth.getBalance(eth.accounts[1]))
0
解鎖傳出帳號,不然不能轉出。personal.unlockAccount(帳號, 密碼, 300)
personal.unlockAccount("0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6", "", 300)
true
轉帳操做
eth.sendTransaction({from: '0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6', to: '0xe8abf98484325fd6afc59b804ac15804b978e607', value: web3.toWei(10, "ether")})
"0xb0674a7fee52555d8712f3a1f0f30fbbbf67ff7b5b4b53ab5d131262613215c6"
若是你如今查看轉入帳號,你會發現餘額仍然是 0 ,交易還未成功寫進區塊,寫進區塊的方式是挖礦,因此你必須執行挖礦
miner.start(1)
null
稍後幾分鐘,再次查看轉入帳號,將會看到有10個以太幣入帳。傳出帳號會減小10個以太幣,同時仍然繼續挖礦中。
web3.fromWei(eth.getBalance(eth.accounts[1]))
10
5.3. admin 管理
5.3.1. 顯示節點
顯示當前節點信息admin.nodeInfo
{
enode: "enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@[::]:30303?discport=0",
id: "9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527",
ip: "::",
listenAddr: "[::]:30303",
name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.1",
ports: {
discovery: 0, listener: 30303
},
protocols: {
eth: { difficulty: 131072, genesis: "0x611596e7979cd4e7ca1531260fa706093a5492ecbdf58f20a39545397e424d04", head: "0x611596e7979cd4e7ca1531260fa706093a5492ecbdf58f20a39545397e424d04", network: 123456 }
}
}
節點地址
enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@[::]:30303?discport=0
[::] 是 ipv6 地址,能夠改成 ipv4 地址。
5.3.2. 查看池
admin.peers
[]
5.3.3. 添加節點
admin.addPeer('enode://9f6490ffb5236f2ddc5710ae73d47c740e0a3644bbd2d67029cf4a6c4693d2f470b642fd2cc3507f7e851df60aaeb730a1270b7a477f91ec5b6b17a8a4b40527@172.16.0.1:30303')
5.4. miner 挖礦管理
5.4.1. 開始挖礦
miner.start(2)
null
過幾分鐘後運行web3.fromWei(eth.getBalance(eth.coinbase), "ether")
30
這時咱們已經看到已經產生了30個以太幣。
5.4.2. 中止挖礦
miner.stop()
true
7.1. Error: authentication needed: password or unlock
eth.sendTransaction({from: '0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6', to: '0xe8abf98484325fd6afc59b804ac15804b978e607', value: web3.toWei(1, "ether")})
Error: authentication needed: password or unlock
at web3.js:3143:20 at web3.js:6347:15 at web3.js:5081:36 at <anonymous>:1:1
解鎖轉出帳號
personal.unlockAccount("0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6", "your_password", 300) true eth.sendTransaction({from: '0x83fda0ba7e6cfa8d7319d78fa0e6b753a2bcb5a6', to: '0xe8abf98484325fd6afc59b804ac15804b978e607', value: web3.toWei(1, "ether")}) "0xd9e8c8fdc71e24ee8052048de4ff0acd7157b872393f37344c8ec2083f3fe48f"