I'm using ethers.js but any answer will be okay !

I'm trying to access a contract's constructor's parameters that was used when deployed to make sure the contract has not been modified before being deployed by a user.

I'm able to get the code from the contract with ethers.js function provider.getCode(_address) but it doesn't include the parameters passed in the constructor of the contract.

Anyone know how this could be done ?

3 Answers 3


If you have the source code, you can determine the parameters from the getCode. The way a contract with constructor parameters is deployed to the network is literally just concatenating the contract's bytecode with the ABI encoded parameters.

For example, see the AirDropToken code and the transaction that deployed it.

You will notice the data in the transaction begins with the contract byte code and has a little extra on the end:


If we decode this (using the source code, we know the constructor parameters):

var ethers = require('ethers');

// Types from the constructor
var types = [ 'string', 'string', 'uint8', 'bytes32', 'uint256' ];

// data is '0x' + the above lines
ethers.utils.AbiCoder.defaultCoder.decode(types, data);
/* [ 'Pi Day N00b Token',
 *   'PIE',
 *   18,
 *   '0xdc03b7993bad736ad595eb9e3ba51877ac17ecc31d2355f8f270125b9427ece7',
 *   BigNumber { _bn: <BN: 0> } ]

It's not possible to access those parameters after a generic smart contract was deployed by a third party.

Depending on what exactly you're trying to accomplish and how much control you have on the smart contracts being deployed, here are a few options:

  • check the values that these parameters influence, like the totalSupply if you're deploying ERC20 smart contracts. I'm thinking that if a parameter doesn't influence the state of the smart contract in any way, it isn't an important parameter, so you don't actually care to check it.
  • if you have can influence the smart contract code that you want to watch, create a custom event, let's say ContractDeployed, fire it from the constructor with the parameters that you want, then check the events generated by that smart contract

If the contract is verified on etherscan, you can now find the constructor parameters at the bottom of the #code tab under "Constructor Arguments"

contract code on etherscan

Your Answer

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

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