以下を実行したらできました。
$ from=0x... # 送金元アドレス
$ to=0x... # 送金先アドレス
$ gas=21000 # gasの量
$ gasprice=50000000000 # gasの値段, この変数の代わりに eth.gasprice としても良いようです
$ geth --exec "eth.sendTransaction({from:'$from',to:'$to',value:eth.getBalance('$from')-$gas*eth.gasprice,gas:$gas,gasPrice:$gasprice})" console
この方法を用いた理由
あるアドレスにある ethereum をすべて別のアドレスに移したいことがありました。しかし、gas や tax の計算が面倒でした。コマンドラインから実行するだけにしました。
参考にしたページ
- How do you compute the right amount of gas and tax to transfer certain amount of money?
- 丸め誤差のため 1 Wei を残すように勧めていますが、私の環境では不要でした。
- 技術者向け Ethereumの基礎知識 (イーサリアム、エセリウム)