LoginSignup
2

More than 5 years have passed since last update.

posted at

Ethereum gethでContractを作成する場合のSolidity versionによる注意点

・Ethereum gethでContractを作成する場合のSolidity versionによる注意点をまとめました。
 [今回使用したSolidity version 0.4.9]

【本文】

EthereumのContractをgethで記述しコンパイル後、登録する際、
Solidity versionが0.4.9だと一部記述が変更されているので注意。
(※自分も結構悩んだので、備忘の意味も込めて共有。。。)

具体的には、以下のようなContractを作成する場合、

(Contractの例)
※『Ethereum入門』-Contractを作成する- に記載されたContract作成例を参照しました。


contract SingleNumRegister {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}


geth上で

(1.ソースを定義)

var source = "contract SingleNumRegister { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) { return storedData; }}"

(2.コンパイル)

var sourceCompiled = eth.compile.solidity(source)

(3.ABI情報を取得)

var contractAbiDefinition = sourceCompiled.SingleNumRegister.info.abiDefinition

(4.コントラクトを作成)

var sourceCompiledContract = eth.contract(contractAbiDefinition)

(5.トランザクションを生成・送信)

var contract = sourceCompiledContract.new({from:eth.accounts[0], data: sourceCompiled.SingleNumRegister.code})

という流れであったが、
Solidity version 0.4.9では、(3)及び(5)の記述は以下の通りに一部変更となる。

【変更箇所】

sourceCompiled.SingleNumRegister ⇒ sourceCompiled['<stdin>:SingleNumRegister']

(3.ABI情報を取得)

var contractAbiDefinition = sourceCompiled['<stdin>:SingleNumRegister'].info.abiDefinition

(5.トランザクションを生成・送信)

var contract = sourceCompiledContract.new({from:eth.accounts[0], data: sourceCompiled['<stdin>:SingleNumRegister'].code})

【参考】

・『Ethereum入門』-Contractを作成する-
https://book.ethereum-jp.net/first_use/contract.html

・"Ethereum Beta"
http://ethereum.stackexchange.com/questions/11912/unable-to-define-greetercontract-in-the-greeter-tutorial-breaking-change-in-sol

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
What you can do with signing up
2