Can decode receipt.logs, but not an input for the same transaction
abi-decoder works great for receipt.logs, but now I want to process pending transaction, so I need to decode an input. But it returns undefined.
Here is an example (transaction, 0x exchange ABI):
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws'))
const abiDecoder = require('abi-decoder')
const contract_artifacts = require('@0x/contract-artifacts')
Object.keys(contract_artifacts).forEach(function(key,index) {
abiDecoder.addABI(contract_artifacts[key].compilerOutput.abi)
})
const tx = '0xdedeeb95961f8ce3eed570abec386759f45ce29b694993a3916d2001ed41bd37'
web3.eth.getTransactionReceipt(tx).then(receipt=>{ console.log(abiDecoder.decodeLogs(receipt.logs)) })
It works great, there are three decoded events. But if I'm trying
web3.eth.getTransaction(tx).then(transaction=>{console.log(abiDecoder.decodeMethod(transaction.input))})
or just
abiDecoder.decodeMethod('0xb4be83d500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000007c4c5a0e0ae4700000000000000000000000000000000000000000000000000000000000002a00000000000000000000000003496b716605d96ecb50c10fea2e0baf11439bd7c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a258b39954cef5cb142fd567a46cddb31a6701240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018ca8441e3dfb5be600000000000000000000000000000000000000000000000000de0b6b3a764004f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c35f0b10000000000000000000000000000000000000000000000000000016832b0cc35000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000024f47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024f47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000421bee193754d40cb289ab679379163d91e259b19cd4d3ddfc6de1890a2301a301337fa8518c89e9a67e5038f5de3b1d9664ac302c62fc5f65b212b576888eb3ac4f03000000000000000000000000000000000000000000000000000000000000')
then I'm getting undefined (however I can decode this data using ethereum-tx-decoder and 0x exchange ABI).
It looks like an issue, but maybe I'm just doing something wrong?
Although this library works for most transactions, this code is somewhat outdated now because solidity added more complicated data types. It does not support structs or multi-dimensional arrays in function input. Your transaction (to 0x protocol v2) makes use of structs.
I have a fork that handles (nested) structs and multi-arrays https://github.com/DeltaBalances/abi-decoder, however I only updated it as far as I personally needed. There might be other datatypes that I missed and I did not yet add more test cases.