I've been able to decode the inputs to a contract function transaction given the ABI as follows:

var myFunction = contract.GetFunction("MyFunction");
var myFunctionTxn = await contract.Eth.Transactions.GetTransactionByHash
var inputs = myFunction.DecodeInput(myFunctionTxn.Input);

However, now I would like to do the same (i.e. retrieve a transaction hash and then decode the constructor inputs) for the constructor itself. I've looked at the ContractABI.Functions - I can see both the Constructor and the Functions, but the types are not compatable.

Also, I can see the types of the inputs from this, but unfortunately not the values:

var ctor = contract.ContractBuilder.ContractABI.Constructor;

Is there an equivalent for DecodeInput for constructors?

From here, it looks like this must be possible

  • 1
    if you have the ABI of this contract, this must be possible just the same way as decoding input of any other method. – Nulik Aug 25 '18 at 15:15

Based on a brief conversation on Gitter with Nethereum's Juan Blanco, I'm using the code from the ConstructorCallDecoder to decode the Constructor.

using Nethereum.Web3;
var contract = _ethClient.Eth.GetContract(_contractAbi, contractAddress);
var ctorTransaction = await contract.Eth.Transactions.GetTransactionByHash
var decodedCtor = new ConstructorCallDecoder()
        pocoToPopulate, _contractByteCode, ctorTransaction.Input);


  • _contractAbi is the ABI for the smart contract
  • contractAddress is the address of the contract instance
  • constructorTransactionHash is the transaction hash of the constructor
  • _contractByteCode is the byte code of the Smart Contract
  • pocoToPopulate is an instance of a class decorated with the necessary Parameter attributes to receive the decoded parameters.

There are likely simpler ways to do this in future (e.g. without the redundancy of requiring both ABI and ByteCode to do the decoding), but this is good enough for me right now.

|improve this answer|||||
  • Hello StuartLC, your revert here did give me hope but i am getting below error using this method : System.OverflowException: Value was either too large or too small for an Int32.............. By anychance do you have any code repo which i can use for reference. – logeekal May 28 '19 at 10:38
  • @logeekal those kinds of errors usually result from not matching the provided ABI, and bytecode to the same version that was used to actually write at the contract address. It might also mean that your contract address or transaction hash don't add up. In the above we're using the constructor but this should work for any transaction on the contract – StuartLC May 28 '19 at 11:42

Your Answer

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

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