2

I am trying to decode the input field of this transaction as below,

const decodedInput = abiDecoder.decodeMethod(transaction.input);

but decodedInput returns undefined despite the my ABI having the entry for swap (as below - taken from the contract's ABI in Etherscan)!

  {
    inputs: [
      {
        components: [
          {
            internalType: 'address',
            name: 'tokenAddress',
            type: 'address',
          },
          {
            internalType: 'uint256',
            name: 'amountIn',
            type: 'uint256',
          },
          {
            internalType: 'address',
            name: 'receiver',
            type: 'address',
          },
          {
            internalType: 'bytes',
            name: 'permit',
            type: 'bytes',
          },
        ],
        internalType: 'struct OdosRouter.inputToken[]',
        name: 'inputs',
        type: 'tuple[]',
      },
      {
        components: [
          {
            internalType: 'address',
            name: 'tokenAddress',
            type: 'address',
          },
          {
            internalType: 'uint256',
            name: 'relativeValue',
            type: 'uint256',
          },
          {
            internalType: 'address',
            name: 'receiver',
            type: 'address',
          },
        ],
        internalType: 'struct OdosRouter.outputToken[]',
        name: 'outputs',
        type: 'tuple[]',
      },
      {
        internalType: 'uint256',
        name: 'valueOutQuote',
        type: 'uint256',
      },
      {
        internalType: 'uint256',
        name: 'valueOutMin',
        type: 'uint256',
      },
      {
        internalType: 'address',
        name: 'executor',
        type: 'address',
      },
      {
        internalType: 'bytes',
        name: 'pathDefinition',
        type: 'bytes',
      },
    ],
    name: 'swap',
    outputs: [
      {
        internalType: 'uint256[]',
        name: 'amountsOut',
        type: 'uint256[]',
      },
      {
        internalType: 'uint256',
        name: 'gasLeft',
        type: 'uint256',
      },
    ],
    stateMutability: 'payable',
    type: 'function',
  }

I've check out related links, Abi-decoder returns undefined & myContract.getPastEvents returns undefined event, but they are quite different from my problem.

1
  • I think your problem is that abi-decoder hasn't been updated for several years. I'd suggest to look for alternatives like ethersjs or web3.js.
    – Ismael
    Dec 1, 2023 at 3:20

1 Answer 1

2
+50

The problem seems related to how abi-decoder computes the function identifier (the hash of the function signature); in particular, it associates swap function to the 0x899a73f4 ID and not to the correct 0xf17a4546.

As pointed out by Ismael, the project has been stale for a few years now, and this is a known issue, so I suggest using a more updated library to execute the decoding, i.e., ethers.js's AbiCoder.

As a workaround, if you still want to stick with abi-decoder, you can replace the function ID like this:

const decodedInput = abiDecoder.decodeMethod(transaction.input.replace('0xf17a4546','0x899a73f4'));

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.