LoginSignup
2
0

More than 5 years have passed since last update.

Ethereum のローカルで作った testnet のコントラクト関数の戻り値が取得できない

Posted at

どうしたらおこったのか

このようなジェネシスブロックの設定を作成

genesis.json
{
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x0",
  "gasLimit": "0x8000000",
  "difficulty": "0x4000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}

ブロックチェーンを初期化

geth-inti.sh
#!/bin/bash
geth \
  --datadir ~/test-net-ethereum \
  init ~/test-net-ethereum/genesis.json

browse-solidity でコントラクトをデプロイ,コントラクト関数を実行

browse-solidity JavaScript VM 設定では戻り値が得られる

browse-solidity Web3 Provider だと以下のエラー

Value: "0x"
Decoded: Failed to decode output: Error: Invalid offset: 0

なぜおこったのか

  1. Ethereumのバージョン「Homestead」のフォーク前後にデプロイされたコントラクトの呼び出しの処理が異なる
  2. 最新の web3.js だと「Homestead」のフォーク後にデプロイされたコントラクトじゃないとエラーが出る
  3. 上記のジェネシスブロックの設定で,初期化すると,すべてのブロックが「Homestead」前にデプロイされてた状態になる

対処法

genesis.json
{
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x0",
  "gasLimit": "0x8000000",
  "difficulty": "0x4000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {},
  "config": {
    "homesteadBlock": 0
  }
}

ジェネシスブロックの設定に 0ブロック以降が,「Homestead」であるという設定を付け加える

chaindata で破棄して,ブロックチェーンを初期化で正常に呼び出せるようになった

参考

2
0
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
2
0