LoginSignup
1
0

More than 1 year has passed since last update.

【Solidity】Error: invalid argument 0: json: cannot unmarshal hex string without 0x~の対処法

Posted at

こちらは、表題エラーに対する汎用的な対処法ではなく、
以下の状況にて発生したエラーに対する原因と対応です。

事象

https://book.ethereum-jp.net/first_use/contract
こちらの「Ethereum入門」に沿ってコントラクトコードを作成していた時に、
ソースコードをコンパイル後、

var myContract = contract.new({ from: eth.accounts[0], data: bin})

を実行した時に以下のエラーが発生。

Error: invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go struct field TransactionArgs.data of type hexutil.Bytes
	at web3.js:6365:37(47)
	at send (web3.js:5099:62(35))
	at web3.js:3021:48(124)
	at <eval>:1:30(13)

原因

コンパイル実行後に生成されるバイナリをvarで宣言する際にPrefixに0xをつける必要があった。

var bin = "608060405234801561001057600080fd5b50610 ~(省略)"
↓ 
var bin = "0x608060405234801561001057600080fd5b50610 ~(省略)"

簡単な話でした。無事コントラクトを作成することができました。

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