2024-03-25



Ubuntu Server 21.10でイーサリアムブロックチェーン【その1】
Ubuntu Server 21.10でイーサリアムブロックチェーン【その2】
Ubuntu Server 21.10でイーサリアムブロックチェーン【その3】
続きです。今回はgethを外部から使う用の様々な立ち上げかたをメモしてみます。
1、最初からアカウントのアンロックがされた状態で起動する
毎回personal.unlockAccountするのが面倒な場合有用です。
パスワードファイルの作成
任意のファイルに1行1パスワードな形で書いて保存しておきます。ここではeth_test/.gethpassとします。
vi eth_test/.gethpass hoge1 hoge2
1行目がアカウント1のパスワード、2行目がアカウント2のパスワードです。
本人のみ読み取り可にします。
cat eth_test/.gethpass hoge1 hoge2 chmod go-rwx eth_test/.gethpass
対応アカウントとパスワードファイルを指定して起動
geth --networkid "15" --nodiscover --rpc.allow-unprotected-txs --allow-insecure-unlock --unlock 0,1 --password "/home/hogeuser/eth_test/.gethpass" --datadir "/home/hogeuser/eth_test" console 2>> /home/hogeuser/eth_test/geth_err.log
2、デーモンプロセスとしてバックグラウンド起動しコンソールは別途接続
サーバープロセスとしてバックグラウンド実行するには、consoleを外して&をつけ、cacheを指定し起動する。SSH接続が切れても継続するようにnohupをつけている。
nohup geth --networkid "15" --nodiscover --rpc.allow-unprotected-txs --cache 2048 --datadir "/home/hogeuser/eth_test" 2>> /home/hogeuser/eth_test/geth_err.log &
別途コンソール接続
eth_test/geth.ipcというUNIXドメインソケットファイルがあるので、それを指定して接続。
geth --datadir "/home/hogeuser/eth_test" attach ipc:/home/hogeuser/eth_test/geth.ipc
なお、デーモンプロセスを終了するには
ps aux | grep hogeuser
などとして、gethのプロセス群を発見してひたすらkillする必要がある。
3、HTTP/Web API接続可能にして起動する
ポート番号は自分で決める。ここでは8575。
geth --http --http.addr "0.0.0.0" --http.port 8575 --http.api "web3,eth,net,personal" --http.corsdomain "*" --rpc.allow-unprotected-txs --datadir "/home/hogeuser/eth_test" --nodiscover --networkid 15 console 2>> /home/hogeuser/eth_test/geth_err.log
外部からWeb API経由で接続テストをする
curlでバージョン情報取得APIを打ってみる。
curl -X POST http://127.0.0.1:8575/ --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' -H "Content-Type: application/json" {"jsonrpc":"2.0","id":1,"result":"Geth/v1.10.17-unstable-2352c722/linux-amd64/go1.17.5"}
4、マイニングを開始した状態で起動する
※マイニングにはPCの大量の電力を消費します。自己責任注意※
geth --mine --miner.threads 4 --identity "sampleNode" --rpc.allow-unprotected-txs --datadir "/home/hogeuser/eth_test" --nodiscover --networkid 15 console 2>> /home/hogeuser/eth_test/geth_err.log
eth.mining true miner.stop() null
5、まとめの一括起動
1~4すべてを組み合わせたバックグラウンド起動は以下のようになる。
nohup geth --mine --miner.threads 4 --identity "sampleNode" --http --http.addr "0.0.0.0" --http.port 8575 --http.api "web3,eth,net,personal" --http.corsdomain "*" --networkid "15" --nodiscover --rpc.allow-unprotected-txs --cache 2048 --allow-insecure-unlock --unlock 0,1 --password "/home/hogeuser/eth_test/.gethpass" --datadir "/home/hogeuser/eth_test" 2>> /home/hogeuser/eth_test/geth_err.log &
次回はブロックチェーン上でプログラムを実行できるスマートコントラクトを作成してみます。
Ubuntu Server 21.10でイーサリアムブロックチェーン【その5】
※本記事内容の無断転載を禁じます。
ご連絡は以下アドレスまでお願いします★
Debian 12でsshからshutdown -h nowしても電源が切れない場合
【Windows&Mac】アプリのフルスクリーンを解除する方法
Debian 12でtsコマンドが見つからないcommand not found
Debian 12でsyslogやauth.logが出力されない場合
Debian 12で固定IPアドレスを使う設定をする
Debian 12 bookwormでNVIDIA RTX4060Ti-OC16GBを動かす
【Debian】apt updateでCD-ROMがどうのこうの言われエラーになる場合
【Debian】あるはずのコマンドが無いと言われる場合
nohupで常時起動したPythonスクリプトがログを出力しない場合
Windows11+WSL2でUbuntuを使う【2】ブリッジ接続+固定IPの設定
【Windows10】リモートデスクトップ間のコピー&ペーストができなくなった場合の対処法
Windows版Google Driveが使用中と言われアンインストールできない場合
【Apache】サーバーに同時接続可能なクライアント数を調整する
【C/C++】小数点以下の切り捨て・切り上げ・四捨五入
【ひかり電話+VoIPアダプタ】LANしか通ってない環境でアナログ電話とFAXを使う
Intel Macbook2020にBootCampで入れたWindows11 Pro 23H2のBluetoothを復活させる
【OpenSSL1.1】Diffie-Hellman(ディフィ・ヘルマン)方式の鍵交換を行う
Googleファミリーリンクで子供の端末の現在地がエラーで取得できない場合