LoginSignup
28
9

More than 5 years have passed since last update.

go-ethereum(geth)でSolidityのコンパイルが出来ない場合

Last updated at Posted at 2017-07-02

Ethereumの勉強をしていたら参考にしていた手順が古くなっておりちょっと手間取ったので対処法などを記載する。

gethでのコンパイルが出来ない

Ethereum のコントラクトを勉強する過程で少し前に発行された本やwebの記事(Ethereum入門)などを参考にしていると、
go-etereum(geth)にsolcを導入してgeth上でコンパイルする前提で進められている場合が多い。

しかし、gethのバージョン1.6以降ではコンパイラのサポートを辞めてしまったようだ。
https://github.com/ethereum/EIPs/issues/209
そのため、コンパイラの設定関連のコマンドは軒並みエラーになってしまう。
最初は自分の環境構築ミスを疑って色々試行錯誤してしまったためかなり時間をとられてしまった。

>  admin.setSolc("path_to_your_solc")
TypeError: 'setSolc' is not a function
    at <anonymous>:1:2

> eth.getCompilers()
Error: The method eth_getCompilers does not exist/is not available
    at web3.js:3104:20
    at web3.js:6191:15
    at web3.js:5004:36
    at <anonymous>:1:1

代替手段

別の手段でコンパイルしてからデプロイすればよい。
Browser-Solidityを使う場合の手順

  1. Browser-Solidity上でコードを書く
  2. コードを書き終わったら、右側のメニューにある「Contract details (bytecode, interface etc.)」をクリック


3. 「Web3 deploy」のテキストボックスに出力された内容をコピペ

  1. コンストラクタの引数がある場合は「var _numProposals = /* var of type uint8 here */ ;」などになっているので値の部分を適当に置き換えてgethのコンソールに貼り付ける。 3.png

この時点でブロックチェーンへのコントラクトの送信が出来ているので、あとは採掘を実行することでコントラクトを登録してアドレスが付与される。

28
9
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
28
9