1. Chạy geth thông tường
2. Tạo sẵn 2 tài khoản
3. Tắt geth đi
4. Tạo một thư mục mới ví dụ /Users/monkey/geth
5. Tạo 1 genesis block trong thư mục /Users/monkey/geth
kiểu:
{ "config": { "chainId": 15, "homesteadBlock": 0 }, "difficulty": "1", "gasLimit": "9999999", "nonce": "0xdeadbeefdeadbeef", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "alloc": { "tài khoản đầu tiên bạn đã tạo": { "balance": "30000" }, "tài khoản thứ 2 bạn đã tạo": { "balance": "50000" } } }
6. Copy thư mục keystore từ thư mục của Ethereum vào thư mục /Users/monkey/geth
7. Chạy lệnh khởi tạo:
geth --datadir . init genesis.json
8. Chạy lệnh để start local node:
geth --syncmode fast --cache 512 --ipcpath ~/Library/Ethereum/geth.ipc --networkid 1234 --datadir . --http --http.api personal,eth,net,web3
9. Thử test bằng cách gọi curl:
curl --location --request GET 'http://localhost:8545/' \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "method":"eth_accounts", "params":[], "id":1 }'
10. Kiểm tra thử balance của 1 tài khoản:
curl --location --request GET 'http://localhost:8545/' \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "method":"eth_getBalance", "params":[ "địa chỉ tài khoản", "latest" ], "id":1 }'
Tham khảo thêm tại đây.
Sharing