10

I want to verify a contract code on Etherscan, but don't know how to get the arguments in ABI-encoded format. I have the source code and the interface in JSON. Is there some tool I can use, or some easy way of getting the JSON to the ABI format?

Note: I used just the "Deploy Contract" from Ethereum Wallet (Mist), no fancy compiler or anything.

The source code: https://gist.github.com/crutor0x/45cd845349345190458df7f7412654e8

JSON ABI: https://gist.github.com/crutor0x/dd97e9593ffb696bfb583481dccb86d9

Contract address: 0x3c75226555fc496168d48b88df83b95f16771f37

15

The page "Verify Contract" ask for "Constructor Arguments ABI-encoded".

In your case the constructor has no parameters, so you can leave such field empty.

In the general case when your constrctor has parameters you can proceed as follow:

You can use ethereumjs-abi to encode/decode the parameters for transaction calls.

Let's suppose your constructor is MyToken(address _to, uint256 _value, bool _enabled). The parameters types are ["address", "uint256", "bool"].

If you have created the contract MyToken("0x1234567812345678", 0x314159268, true). Then the parameters values are ["0x1234567812345678", "0x314159268", true].

Then you can encode the values with rawEncode(parameterTypes, parameterValues).

var abi = require('ethereumjs-abi')

var parameterTypes = ["address", "uint256", "bool"];
var parameterValues = ["0x1234567812345678", "0x314159268", true];

var encoded = abi.rawEncode(parameterTypes, parameterValues);

console.log(encoded.toString('hex'));

On execution it will output

000000000000000000000000000000000000000000000000123456781234567800000000000000000000000000000000000000000000000000000003141592680000000000000000000000000000000000000000000000000000000000000001

  • I tried also this but for some reason I get this error: "Error: Cannot find module 'ethereumjs-abi'" github.com/ethereumjs/ethereumjs-abi/issues/51 – NineCattoRules Sep 21 '17 at 17:29
  • @NineCattoRules Did you install ethereumjs-abi in your npm project? – Ismael Sep 21 '17 at 23:23
  • I've tried locally and globally. I tried also npm cache verify but always get the same error again. And path on Win to node.js is correctly set. – NineCattoRules Sep 22 '17 at 10:52
  • 2
    @NineCattoRules I've tried my example and it works without problems (Windows 7 x64). In an empty dir create the project npm init -y, add ethereumjs-abi npm i --save ethereumjs-abi, save code as index.js, and then run npm index.js. It display the same output. I'd suggest to try in a different computer, or in a virtual machine. But this is out of scope of this forum, you are better asking in stackoverflow's javascript section. – Ismael Sep 22 '17 at 15:23
  • 2
    Yes it works! Last command is node index.js – NineCattoRules Sep 22 '17 at 16:30
3

In case you want to use a simple online tool to encode parameters you may use https://abi.hashex.org

You can enter abi to automatically parse parameter types or just enter them manually. In Function type selector constructor should be picked.

Here is example of using this service, at the bottom are abi-encoded parameters that you enter in etherscan.io constructor parameters field. parameters

0

The site https://abi.hashex.org does not work for me and it's always complaining "enter correct JSON".

You can try this site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy