4

I want to verify a contract on Etherscan.io, but I am not able to find the correct Constructor Arguments. I tried everything which is explained on StackExchange, but cannot get it to verify...

The contract address is 0x9b81b233235af9024f3cffa33e19de54eee31f44

I used compiler v. 0.4.16, NO optimization

Any help would be higly appreciated

 function TokenERC20(
        uint256 initialSupply,
        string tokenName,
        string tokenSymbol
    ) public {
        totalSupply = initialSupply * 10 ** uint256(decimals);  // Update total supply with the decimal amount
        balanceOf[msg.sender] = totalSupply;                // Give the creator all initial tokens
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
    }
8
  • Can't you just decode the arguments? It's hex format. Jan 26, 2018 at 3:47
  • I tried, but I keep on getting error from Etherscan, I must make some mistake Jan 26, 2018 at 8:06
  • I also used this tool, abi.sonnguyen.ws but nothing to do, it won't verify. Jan 26, 2018 at 8:40
  • this is the constructor function I have: Jan 26, 2018 at 8:41
  • 1
    When I generate the constructor codes using the tool abi.sonnguyen.ws I get exactly the same output as I get from Etherscan.io on tha page displaying the contract byte code Jan 26, 2018 at 9:31

1 Answer 1

4

The parameters for the constructor are appended to the contract. If you look at the "Input Data" in the contract creation transaction https://etherscan.io/tx/0x08e63522fb7a4e1a46ee35cfab7767ec98c5d727da897a9c8cfb7e27c15861a0 and scroll to the end your parameters are there.

000000000000000000000000000000000000000000000000000000003b9aca01
0000000000000000000000000000000000000000000000000000000000000060
00000000000000000000000000000000000000000000000000000000000000a0
0000000000000000000000000000000000000000000000000000000000000001
4b00000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000003
e282ad0000000000000000000000000000000000000000000000000000000000

This script will decode the block using the parameters from the constructor and recreate them to be sure

const abi = require('ethereumjs-abi');

function decodeTx() {
  const data = Buffer.from(`000000000000000000000000000000000000000000000000000000003b9aca01000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000014b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e282ad0000000000000000000000000000000000000000000000000000000000`, 'hex');

  const decoded = abi.rawDecode(['uint256', 'string', 'string'], data);

  console.log(`Decoded: ${JSON.stringify(decoded, null, '  ')}`);

  const params = [
    '0x3b9aca01',
    'K',
    '₭'
  ];

  const encoded = abi.rawEncode(['uint256', 'string', 'string'], params);

  console.log(`Encoded: ${encoded.toString('hex')}`);
}

decodeTx();

The output is

Decoded: [ "3b9aca01", "K", "₭" ]

Encoded: 000000000000000000000000000000000000000000000000000000003b9aca01000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000014b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e282ad0000000000000000000000000000000000000000000000000000000000

3
  • Thanks indeed for your answer, but this is the code I used several times, and I keep on getting the same error: Note: Contract was created during Txn# [0x08e63522fb7a4e1a46ee35cfab7767ec98c5d727da897a9c8cfb7e27c15861a0] Result: Does not match the input creation bytecode found at this address Sorry! The Compiled Contract ByteCode for 'KToken' does NOT match the Contract Creation Code for [0x9b81b233235af9024f3cffa33e19de54eee31f44]. Contract name(s) found: 'KToken' , 'TokenERC20' , 'owned' , 'tokenRecipient' Unable to Verify Contract source code. Jan 27, 2018 at 8:55
  • The parameters are correct, then something else is wrong, like your source code, the compiler version, the optimization settings, etc. There's another verification page that allows to set how many runs the optimizer used etherscan.io/verifyContract2. Are you using truffle to deploy or another tool?
    – Ismael
    Jan 27, 2018 at 15:45
  • 2
    If you are using truffle to deploy, the easiest way is using my plugin truffle-plugin-verify, which retrieves all necessary information (constructor params from Etherscan, rest from Truffle artifact files) and automatically submits the code for verification at Etherscan. Dec 16, 2019 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.