LoginSignup
1
2

More than 5 years have passed since last update.

gethコマンド

Posted at

事前準備

・Download geth from https://ethereum.github.io/go-ethereum/downloads/

mkdir ~/work/geth
cp /path/to/download/geth ~/work/geth/
echo "export PATH=~/work/geth:$PATH" >> ~/.bash_profile && source ~/.bash_profile
mkdir ~/work/geth/private_net
vim genesis.json
cd ~/work/geth/private_net
genesis.json
{
    "config":{
        "chainId": 33,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "nounce": "0x0000000000000033",
    "timesatamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": "0x8000000",
    "difficulty": "0x100",
    "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",
    "alloc": {}
}

プライベートネットワーク初期化

geth --datadir ./ -init ./genesis.json

プライベートネットワーク起動

geth --networkid "10" --nodiscover --datadir ~/work/geth/private_net --rpc --rpcaddr "localhost" --rpcport "8545" --rpccorsdomain "*" --rpcapi "eth,net,web3,personal" --targetgaslimit "20000000" console 2>> ~/work/geth/private_net/error.log

アカウント作成

> personal.newAccount("password")

アカウントの確認

> eth.accounts
> eth.accounts[0]

コインベースアカウントの確認

> eth.coinbase

コインベースアカウントの変更

> miner.setEtherbase(eth.accounts[1])

ブロック内容の確認

> eth.getBlock(0)

マイニングの開始

> miner.start(1)
*()内はマイニングするスレッド数

マイニングの停止

> miner.stop()

マイニング中かどうかの確認

> eth.mining

ブロック数の確認

> eth.blockNumber

コインベース残高の確認(単位wei)

> eth.getBalance(eth.accounts[0])

コインベース残高の確認(単位ether)

> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")

アカウントのロック解除

> personal.unlockAccount(eth.accounts[0])

etherの送金

> eth.sendTransaction({from: eth.accounts[0], to: eth3.accounts[2], value:web.toWei(5, "ether")})

トランザクションの確認

> eth.getTransaction("hash値")

トランザクションレシートの確認

> eth.getTransactionReceipt("hash値")

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2