Giter Site home page Giter Site logo

consensys / abi-decoder Goto Github PK

View Code? Open in Web Editor NEW
626.0 27.0 215.0 1.44 MB

Nodejs and Javascript library for decoding data params and events from ethereum transactions

License: GNU General Public License v3.0

JavaScript 100.00%
ethereum ethereum-dapp

abi-decoder's Introduction

abi-decoder

Nodejs and Javascript library for decoding data params and events from etherem transactions

Install

npm install abi-decoder
bower install abi-decoder

Instantiate

<script src="bower_components/abi-decoder/dist/abi-decoder.js"> // Javascript
const abiDecoder = require('abi-decoder'); // NodeJS

Add ABI's

Need to pass the ABI's manually to the library in order to be able to decode params later

const testABI = [{"inputs": [{"type": "address", "name": ""}], "constant": true, "name": "isInstantiation", "payable": false, "outputs": [{"type": "bool", "name": ""}], "type": "function"}, {"inputs": [{"type": "address[]", "name": "_owners"}, {"type": "uint256", "name": "_required"}, {"type": "uint256", "name": "_dailyLimit"}], "constant": false, "name": "create", "payable": false, "outputs": [{"type": "address", "name": "wallet"}], "type": "function"}, {"inputs": [{"type": "address", "name": ""}, {"type": "uint256", "name": ""}], "constant": true, "name": "instantiations", "payable": false, "outputs": [{"type": "address", "name": ""}], "type": "function"}, {"inputs": [{"type": "address", "name": "creator"}], "constant": true, "name": "getInstantiationCount", "payable": false, "outputs": [{"type": "uint256", "name": ""}], "type": "function"}, {"inputs": [{"indexed": false, "type": "address", "name": "sender"}, {"indexed": false, "type": "address", "name": "instantiation"}], "type": "event", "name": "ContractInstantiation", "anonymous": false}];
abiDecoder.addABI(testABI);

Decode Tx data

const testData = "0x53d9d9100000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a6d9c5f7d4de3cef51ad3b7235d79ccc95114de5000000000000000000000000a6d9c5f7d4de3cef51ad3b7235d79ccc95114daa";
const decodedData = abiDecoder.decodeMethod(testData);

Decode Logs from Tx Receipt

web3.eth.getTransactionReceipt("0x9199e262aaab0a6ec99558b3e9f42397c07a2bb9c6befb637643aebfb03cc32a", function(e, receipt) {
  const decodedLogs = abiDecoder.decodeLogs(receipt.logs);
});

abi-decoder's People

Contributors

bh2smith avatar chikeichan avatar danjm avatar denisgranha avatar dependabot[bot] avatar eordano avatar forshtat avatar krzkaczor avatar kumavis avatar nionis avatar spalladino avatar ziogaschr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

abi-decoder's Issues

Where is located abi-decoder.js ?

Hi,
I dont use Bower.

I am using abi-decoder with node.js correctly.

I am trying to use abi-decoder with simple javascript in a website.
In your repository there isnt abi-decoder.js

How is the correct way? Thank you

Event log decode error: BigNumber Error: new BigNumber() not a base 16 number:

Having an issue decoding an event log with [email protected]. Perhaps the problem is with an event string argument, but the error message doesn't point out exactly what it's having an issue with. Here's a simple test case:

const abiDecoder = require('abi-decoder');
const simpleABI = [{
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "name": "tagHash",
        "type": "bytes32"
      }, {
          "indexed": true,
          "name": "firstProposer",
          "type": "address"
      }, {
          "indexed": true,
          "name": "secondProposer",
          "type": "address"
      }, {
          "indexed": false,
          "name": "tagName",
          "type": "string"
      }
    ],
    "name": "TagActivated",
    "type": "event"
}];
const testLog = { 
  address: '0x045f938bd53f87d745938fdb7c36af3a228494b7',
  topics: [ 
    '0xe3be63cadbca73f1ec47cb1e6e478b35a17056c269e8637aa60c65853efe05c2',
    '0x3d03b3af6b873f883e8316435fedcb99ad340ac5d26ff776cfe84e9f6d8e0420'
  ],
  data: '0x000000000000000000000000f2a3047bc98fb43dd782948e88c785475609dce4000000000000000000000000b89c7bf13e8c852d29b3ce7bd1be0e6c47d81b8c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000056c756e7972000000000000000000000000000000000000000000000000000000',
  blockNumber: '0x151',
  transactionHash: '0x4e91ae4d9c76ad68271e647dff9b19a5d876a9cc4ff1fe372cb2009981bad639',
  transactionIndex: '0x0',
  blockHash: '0xcb1e027a0996177a2151f541eaccdc51cce38d1b975f0719c0ca1f4e09b9cac0',
  logIndex: '0x1',
  removed: false 
};
abiDecoder.addABI(simpleABI);
abiDecoder.decodeLogs([testLog])

And the resulting error:

BigNumber Error: new BigNumber() not a base 16 number: 
    at raise (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/bignumber.js/bignumber.js:1177:25)
    at /home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/bignumber.js/bignumber.js:1165:33
    at new BigNumber (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/bignumber.js/bignumber.js:212:28)
    at SolidityTypeString.formatOutputString [as _outputFormatter] (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/web3/lib/solidity/formatters.js:220:19)
    at /home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/web3/lib/solidity/type.js:246:25
    at SolidityTypeString.SolidityType.decode (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/web3/lib/solidity/type.js:247:11)

Let me know if I can provide any more info.

Decoding contract transaction value transferred - Approximating big numbers with e+x

Rinkeby TX

> abiDecoder.decodeMethod("0xa9059cbb0000000000000000000000002147e79d34ee3c4403de8584cfd7fd235141564f00000000000000000000000000000000000000000052ba49a3403d1c26c4b9f4")
{ name: 'transfer',
  params:
   [ { name: '_to',
       value: '0x2147e79d34ee3c4403de8584cfd7fd235141564f',
       type: 'address' },
     { name: '_value',
       value: '1.000116357500001449434629e+26',
       type: 'uint256' } ] }

The actual value transferred is 100,011,635,750,000,000,000,000,000 as shown in rinkeby.etherscan.io

but the decoder gives approximated e+26 value which when parsed into int, we get 100,011,635,750,000,144,293,036,032 - which is higher than actual number.

any pointers?

exception when decoding receipt logs of some transaction

transaction:0x7834632fb74e671317e87551c5969dcf117efaf00c1f16c4e5d66419715e3b37

when decoding the transaction above, got the exception, most other transactions is ok.

const abiDecoder = require('abi-decoder');
abiDecoder.addABI(config.get('ERC20-abi'));
let batch = web3.createBatch();                                                                                                                               
batch.add(web3.eth.getTransactionReceipt.request('0x7834632fb74e671317e87551c5969dcf117efaf00c1f16c4e5d66419715e3b37', receiveTransactionReceipt));                                                                                                                          
batch.execute();

function receiveTransactionReceipt(err, receipt) {
    const decodedLogs = abiDecoder.decodeLogs(receipt.logs);
    console.log(decodedLogs);
}

TypeError: Cannot read property 'slice' of undefined                                                                                                                                 
    at /data/ethereum/wallet_server/node_modules/abi-decoder/index.js:112:40
    at Array.map (<anonymous>)
    at Object._decodeLogs [as decodeLogs] (/data/ethereum/wallet_server/node_modules/abi-decoder/index.js:111:15)
    at Object.receiveTransactionReceipt [as callback] (/data/ethereum/wallet_server/ether_scan/ether-scan-test.js:218:36)
    at /data/ethereum/wallet_server/node_modules/web3/lib/web3/batch.js:59:33
    at Array.forEach (<anonymous>)
    at /data/ethereum/wallet_server/node_modules/web3/lib/web3/batch.js:52:12
    at /data/ethereum/wallet_server/node_modules/web3/lib/web3/requestmanager.js:116:9

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?

Wrong Decoding of Transaction Receipt Logs

Hi,
I am using abiDecoder.decodeLogs(receipt.logs) to decode the logs of my quorum transactions. It decodes the addresses incorrectly in the logs.
For example- My actual account address is - 0x955B26E07213e7724C936b2e6765Ab0BC15bdb17
but the decoded the output address comes - 0x955b26e07213e7724c936b2e6765ab0bc15bdb17

Similary, another account address is - 0x1932c48b2bf8102ba33b4a6b545c32236e342f34
but the decoded output address comes - 0x1932c48b2bF8102Ba33B4A6B545C32236e342f34

I am using abi-decoder version - 2.2.1 with web3 version - 1.2.1.
Please explain the reason behind this irregular behaviour. This wrong decoding occurs in just addresses but rest of the decoded logs output comes correct.

Incorrectly decodes logs [2.x]

For mainnet tx 0x43b9b2006a00f867dcd2df9b9f7f33ac895f935154fe5acb74d51272885cd21e log values are incorectly decoded.

Code sample:

web3.eth.getTransactionReceipt(
  "0x43b9b2006a00f867dcd2df9b9f7f33ac895f935154fe5acb74d51272885cd21e",
  function(e, receipt) {
    const decodedLogs = abiDecoder.decodeLogs(receipt.logs);
    console.log(JSON.stringify(decodedLogs));
  },
);

Prints out for pollId 330000000000000000000000000000000000000000000000000000000000000022 where it should be 34
https://etherscan.io/tx/0x43b9b2006a00f867dcd2df9b9f7f33ac895f935154fe5acb74d51272885cd21e#eventlog

Can't decode if the function has parameters of array of int

Hello,

Thanks for your job !

But i got an issue when i try to decode input of this function :

{ "constant": false, "inputs": [ { "name": "personalPublicKey", "type": "uint256[2]" }, { "name": "inscriptionCode", "type": "bytes32" } ], "name": "askForRegistration", "outputs": [ { "name": "_successful", "type": "bool" }, { "name": "_error", "type": "string" } ], "payable": false, "type": "function" }

This function got a parameter which is an array of int : uint256[2].

When i'm trying to decode the input :
"0x03f81e4bc2d9fba5a3c7528b79a64b5b3ece4fef1c8b9403177fb49050ebd203089df7cb9b5211ed7a2687c8f65821033ea8a52aa5fb5bf2e75e2d28789bf6c59310e332777a33615a67506d77494757476b4e7200000000000000000000000000000000"

I receive the following error :

Uncaught Error: new BigNumber() not a number: 8.8133835242182733293431835969184996744628576634809496506230003714962103334859e+76,7.025349672177732334213228675287293923580409794353518492209036660848106726277e+76
at raise (C:\Developpement\WaveVote\electron-ihm-votant\node_modules\abi-decoder\node_modules\bignumber.js\bignumber.js:1177:25)
[...]
at params.decoded.map (C:\Developpement\WaveVote\electron-ihm-votant\node_modules\abi-decoder\index.js:76:36)

I think the decoder can't decode array of int.

I'm trying to modify the code of your librairy to solve this issue but atm it's not a success.

If you have a solution to propose, you're welcome !

Best regards.

decoding receipt.logs undefined

Hi, I try to use abidDecoder.decodeLogs(), but not working
the code is :

web3.eth.getTransactionReceipt('0x3ceff5f69a3e7440bccc226cc6f860b0bde81d05440c676c8bbf0c0f19585bd4', function(e,receipt){
	console.log('receipt', receipt);
  console.log('receipt log', receipt.logs);
	const decodedLogs = abiDecoder.decodeLogs(receipt.logs);
	console.log('decodedLogs',decodedLogs);
})

And I got the output receipt { blockHash: '0xc581cd0cd611d70119e10b5e472c4935a31c1bf035e251552df8357b44721206', blockNumber: 96803, contractAddress: null, cumulativeGasUsed: 75490, from: '0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98', gasUsed: 32878, logs: [ { address: '0xCAc7000C7dBaa2E33Af15325AF5D435E011C7BdD', topics: [Array], data: '0x00000000000000000000000000000000000000000000000022359c267290d800', blockNumber: 96803, transactionHash: '0x3ceff5f69a3e7440bccc226cc6f860b0bde81d05440c676c8bbf0c0f19585bd4', transactionIndex: 2, blockHash: '0xc581cd0cd611d70119e10b5e472c4935a31c1bf035e251552df8357b44721206', logIndex: 0, removed: false, id: 'log_943b1cf8' } ], logsBloom: '0x00000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000200000000000000000000080000000000000000000000000040000000000000000000000030000000001000000001000000000000', root: '0xa3f6d0955c6918bdb800c7b8e2bbc224e7e0c7d0938d82dc819fa1cb7c469bcf', to: '0xcac7000c7dbaa2e33af15325af5d435e011c7bdd', transactionHash: '0x3ceff5f69a3e7440bccc226cc6f860b0bde81d05440c676c8bbf0c0f19585bd4', transactionIndex: 2 } receipt log [ { address: '0xCAc7000C7dBaa2E33Af15325AF5D435E011C7BdD', topics: [ '0x4c13017ee95afc4bbd8a701dd9fbc9733f1f09f5a1b5438b5b9abd48e4c92d78', '0x4249545452455830300000000000000000000000000000000000000000000000', '0x000000000000000000000000725f637bf6266b62d8a4b8f9ec4e6e346d34998d' ], data: '0x00000000000000000000000000000000000000000000000022359c267290d800', blockNumber: 96803, transactionHash: '0x3ceff5f69a3e7440bccc226cc6f860b0bde81d05440c676c8bbf0c0f19585bd4', transactionIndex: 2, blockHash: '0xc581cd0cd611d70119e10b5e472c4935a31c1bf035e251552df8357b44721206', logIndex: 0, removed: false, id: 'log_943b1cf8' } ] decodedLogs [ undefined ]

I got the right transaction receipt but the abiDecoder.decodeMethod() returns undefined. What's the problem? Thanks!

Multiple signature of the same events (with and without index) not processed correctly

In case an event (log) has a signature of eventName(address arg1) and eventName(indexed address arg1) - the normalised signature is the same (lets say X)

loading multiple ABIs does not help as the latest ABI is saved for handling the X form

Need to save an array of ABIs for each method/log
try handle them in series until one succeed or all of them failed

https://etherscan.io/tx/0xe9dc240d688fb3aa78f2d18bc73812f613f564dcd1768e4e4b96e5ea85c7c6e1

This is an example of a transaction that fails to process
Log 2 and Log 10 are the same, but one has indexed args and the other not
the library tries to handle both of them as indexed so it throws on this line(168)

decodedP.value = decodedP.value.toLowerCase();

since value is undefined

** Relevant probably only for address type

decoding abi

In README:

Need to pass the ABI's manually to the library in order to be able to decode params later

//Add ABI's

const testABI = [{"inputs": [{"type": ....}];
abiDecoder.addABI(testABI);

//Decode Tx data

const testData = "0x53d9d910000........0000a6d9c5f7d4de3cef51ad3b7235d79ccc95114daa";
const decodedData = abiDecoder.decodeMethod(testData);
  1. What's testData? Is it transaction.input? Or what is it?

  2. abiDecoder.addABI(testABI); - does this mean that once I've added some abi (abi1), the method decodeMethod will ONLY be able to decode methods using once specified abi1? What if I have multiple abi-s and multiple methods to decode? In other words, how can I decode a specifi method with a specific abi?

Cannot decode tx data

This is somewhat an edge case but the ERC20 token transfer for this transaction cannot be decoded. I am not sure whether I should open an issue here or @ethersproject/abi.

Sample Code

const abiDecoder = require('abi-decoder');
const testABI = [{
    "constant": false,
    "inputs": [
        {
            "name": "_to",
            "type": "address"
        },
        {
            "name": "_value",
            "type": "uint256"
        }
    ],
    "name": "transfer",
    "outputs": [
        {
            "name": "",
            "type": "bool"
        }
    ],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
}];
abiDecoder.addABI(testABI);
const testData = "0xa9059cbb0000000000000000000000043f47038d2b20566700a38cd718a537103f7696c9000000000000000000000000000000000000000000000000000000000903c63c";
const decodedData = abiDecoder.decodeMethod(testData);
console.log(decodedData);

Exception

/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/array.js:139
                get: function () { throw value; }
                                   ^

_to: value out of range (argument="value", value=20, code=INVALID_ARGUMENT, version=bytes/5.0.1)
    at Logger.makeError (/home/ubuntu/node_modules/@ethersproject/logger/lib/index.js:179:21)
    at Logger.throwError (/home/ubuntu/node_modules/@ethersproject/logger/lib/index.js:188:20)
    at Logger.throwArgumentError (/home/ubuntu/node_modules/@ethersproject/logger/lib/index.js:191:21)
    at Object.hexZeroPad (/home/ubuntu/node_modules/@ethersproject/bytes/lib/index.js:263:16)
    at AddressCoder.decode (/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/address.js:34:45)
    at /home/ubuntu/node_modules/@ethersproject/abi/lib/coders/array.js:93:31
    at Array.forEach (<anonymous>)
    at Object.unpack (/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/array.js:71:12)
    at TupleCoder.decode (/home/ubuntu/node_modules/@ethersproject/abi/lib/coders/tuple.js:39:49)
    at AbiCoder.decode (/home/ubuntu/node_modules/@ethersproject/abi/lib/abi-coder.js:93:22) {
  reason: 'value out of range',
  code: 'INVALID_ARGUMENT',
  argument: 'value',
  value: 20,
  baseType: 'address',
  name: '_to',
  type: 'address'
}

I think that there is a typo in the input data for the address parameter and this causes a problem. There is a 4 instead of 0 (I added spaces before and after to make it more readable.)

Function signiture: 0xa9059cbb
Address: 00000000000000000000000 4 3f47038d2b20566700a38cd718a537103f7696c9
Value: 000000000000000000000000000000000000000000000000000000000903c63c

How to use this library with svelte

Hi!
I'm trying to use this library with svelte but after install it with npm i -D
Besides a low severity vulnerability with yargs-parser, when I try to do

import abiDecoder from 'abi-decoder'; 

it raises a bunch of traces starting with:

Missing shims for Node.js built-ins

So I deduce I'm missing a build process (bower?)
Can you explain this step? I don't use bower
Or even better: can I use this library directly on svelte and rollup?

Thanks

Cannot find module './formatters'

Not sure if my tests are failing for some other reason, but I'm getting these errors in my tests:

Any ideas why it can't find a relative loaded module in a nested module?

Error: Cannot find module './formatters'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
    at Function.Module._load (internal/modules/cjs/loader.js:475:25)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at Object.<anonymous> (/Users/justinkchen/workspace/set-protocol-contracts/node_modules/web3/lib/solidity/coder.js:23:9)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at Object.<anonymous> (/Users/justinkchen/workspace/set-protocol-contracts/node_modules/abi-decoder/index.js:1:23)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at Object.<anonymous> (/Users/justinkchen/workspace/set-protocol-contracts/test/core/setTokenFactory.spec.ts:1:1)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at /Users/justinkchen/workspace/set-protocol-contracts/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/justinkchen/workspace/set-protocol-contracts/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/Users/justinkchen/workspace/set-protocol-contracts/node_modules/mocha/lib/mocha.js:536:10)
    at /Users/justinkchen/workspace/set-protocol-contracts/node_modules/truffle/build/webpack:/~/truffle-core/lib/test.js:125:1```

Invalid continuation byte and Invalid UTF-8 detected

I am having trouble decoding transaction inputs to older transactions found on the blockchain. I am digging through the history of various smart contracts as a kind of "archeological" investigation.

Here is my test program showing the issue for a variety of contracts (APIKey deliberately omitted):

const abiDecoder = require( 'abi-decoder' ) ;
const etherscanApi = require( 'etherscan-api' ).init( APIKey ) ;
const web3Utils = require( "web3-utils" ) ;
const Web3 = require( 'web3' );


async function test( contractName, contractAddress, txHash ) {
        const web3 = new Web3( new Web3.providers.HttpProvider( 'https://mainnet.infura.io/v3/d53c56d7964b40f4b1ed47dec984de12' ) ) ;
        const tx = await web3.eth.getTransaction( txHash ) ;
        const receipt = await web3.eth.getTransactionReceipt( txHash ) ;
        const encodedInput = tx.input ;

        console.log( '\ncontractName', contractName ) ;
        console.log( 'contractAddress', contractAddress ) ;
        console.log( 'txHash', txHash ) ;
        console.log( 'receipt.status', receipt.status ) ;
        console.log( 'encodedInput', encodedInput ) ;

        const encodedAbi = await etherscanApi.contract.getabi( contractAddress ) ;
        var decodedAbi = JSON.parse( encodedAbi.result ) ;

        abiDecoder.addABI( decodedAbi ) ;
        var decodedInput ;
        try{
                decodedInput = abiDecoder.decodeMethod( encodedInput ) ;
        } catch( error ) {
                decodedInput = error.message ;
        }

        console.log( 'decodedInput', decodedInput ) ;
        console.log( 'encodedInput.slice( 2, 10 )', encodedInput.slice( 2, 10 ) ) ;
}

async function main() {
        await test ('StakeDice', '0x4420974a2d98b8b5ee990fc4b32ca66b1c184100', '0xc9d62a2cf62abb1c6726dc64bcba87f39d93d330ebd008ed8d6b3ac76104d9e8' ) ;
        await test( 'Cillionaire', '0x02b97cca6d6a5227e464b2a60ee1a580ea4f7da9', '0xa2a4d1a082a9ee3fb2f9fa33979a0247b0dcf6a47295d281789c02bed49e70b8' ) ;
        await test( 'EOSBetSlots', '0x4a3e0c60f7fa67e8b65c401ddbbf7c17fea5fe40', '0x269d51fd6a00228c76e9a57c40f719292807ef29335d9281e75c51dc8aecab72' ) ;
        await test( 'EtherFlipGold', '0x48d8f22d45e40F34cB7C10799F31246F134E9B7f', '0xc1214a3722ca61685f92dd680846551cdb841fe3fa4d198e6e520023e17007c3' ) ;
        await test( 'EthereumPot', '0x5a13caa82851342e14cd2ad0257707cddb8a31b7', '0x492e1c40d6e8a26bb8b226bb79b815b1a7f6b2a5b17c530912c2f7f938b440b6' ) ;
}

main() ;

Running the code I get:

contractName StakeDice
contractAddress 0x4420974a2d98b8b5ee990fc4b32ca66b1c184100
txHash 0xc9d62a2cf62abb1c6726dc64bcba87f39d93d330ebd008ed8d6b3ac76104d9e8
receipt.status true
encodedInput 0x27dc297ef998bc28180fb745edd710cd10930dd88e6d60d749d0309580c5f45786e6da2800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004c1099aec00000000000000000000000000000000000000000000000000000000
decodedInput Invalid continuation byte
encodedInput.slice( 2, 10 ) 27dc297e

contractName Cillionaire
contractAddress 0x02b97cca6d6a5227e464b2a60ee1a580ea4f7da9
txHash 0xa2a4d1a082a9ee3fb2f9fa33979a0247b0dcf6a47295d281789c02bed49e70b8
receipt.status undefined
encodedInput 0x38bbfa50f1d9916f002d89d9d5bf0db716d1b232d5efe39bc01cd3175744d6f8f07f58ff000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000007658858778c7c140000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c14c50010498c36fc999f7a37ffffe7e4207142d9f708b96f190cfaed75133dba388ac694c2f6db039f926344c918a1d96142a95c332a5403b21e94953a9c75bc27d4290a33044022003bd07a86cb31b9beabbeefa55f9343fdff77afd840da1a43a714948c32e70d1022004f86513ff6689c5553599ccc60da62e063411e484e250545f844a0ba3d1e57ffd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c9034ee368594c76fc4a7cd1faa63873389c910ace310f7926defdbed0df9335a0000000000000000070376ad70262059f46bd8c1a68209d87c5fc7a5ab1ee794ed96c72e210b8cb036304402201928a7176a07cd12634b792760d770eb1b20516f2bb45536fbf8d8f7f6b5ae14022016fc7bd2310822b01a7cfd6ee6945d7ae61d817564e8312534dbd138516329c204089c95cc443809b64b0d21991f613a2d3cf2d60e2c961770814ab715f1273dac90855d05d9ae9d193e7f5f7ad53715eb39ee66de62f443bd42a1b73b5eeaf8e33045022100986406c9e5a118a043c67ff21d4bae45905802843a613fb7f3e9650d275ade9d02202593bd41512c220268c5890892e5adfb3c99e42c425923db49a79c9cc03bd34c00000000000000000000000000000000000000000000000000000000000000
decodedInput Invalid UTF-8 detected
encodedInput.slice( 2, 10 ) 38bbfa50

contractName EOSBetSlots
contractAddress 0x4a3e0c60f7fa67e8b65c401ddbbf7c17fea5fe40
txHash 0x269d51fd6a00228c76e9a57c40f719292807ef29335d9281e75c51dc8aecab72
receipt.status false
encodedInput 0x38bbfa503dd56c1618aff7380e778bf4798377a9975e48f29c30bdcddd57b685d8cf1e4b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000001e48ef0cedd2a26b1530d36d2a509449d8850988416c6cf3340d6ef9167c72000000000000000000000000000000000000000000000000000000000000000001c14c50010498c36fc999f7a37ffffe7e4207142d9f708b96f190cfaed75133dba388ac694c2f6db039f926344c918a1d96142a95c332a5403b21e94953a9c75bc27d4290a33044022003bd07a86cb31b9beabbeefa55f9343fdff77afd840da1a43a714948c32e70d1022004f86513ff6689c5553599ccc60da62e063411e484e250545f844a0ba3d1e57ffd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505ca050cf2a4e30f7667cbdc450e34618f07f8a62611261a2efa97b8f9c701826fd00000000000000001efebb1674c4f6c18db3f1edff0f5d61bd8826b321b1e7327b9c9579b7bde14a8b30440220722eb459dc38a54421f9e517c0cde71d1f2db790f4cba0974b77e578739accdc022050c207f8a2e8392015b13a9fb11be0a3cb22f70ae21a63f3a265b280e099c7af04def38033713f0c5b3bea0f0eeb027f6f50936fe535f841ef1fe305d4fea55884d9a251254e6256c896d4331586ff55449cadb48eddb4470aed039144741e87a13045022100fd4cef1f790222a005e3a353d39ae1e43e5986f30a7f3de56fec1d5c1321035102206463046b56634a52727878b57b8104d23ba1b3326bc40147e50075125fff371600000000000000000000000000000000000000000000000000000000000000
decodedInput Invalid continuation byte
encodedInput.slice( 2, 10 ) 38bbfa50

contractName EtherFlipGold
contractAddress 0x48d8f22d45e40F34cB7C10799F31246F134E9B7f
txHash 0xc1214a3722ca61685f92dd680846551cdb841fe3fa4d198e6e520023e17007c3
receipt.status undefined
encodedInput 0x38bbfa50c300752bf81eb28e5bb5dc0c56a8ab3c5d09b439675fd41507482d1aa20d08b6000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002d0e900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c14c50010498c36fc999f7a37ffffe7e4207142d9f708b96f190cfaed75133dba388ac694c2f6db039f926344c918a1d96142a95c332a5403b21e94953a9c75bc27d4290a33044022003bd07a86cb31b9beabbeefa55f9343fdff77afd840da1a43a714948c32e70d1022004f86513ff6689c5553599ccc60da62e063411e484e250545f844a0ba3d1e57ffd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505cef1af03d86a48b764836e68f153a133c41a9b969795e1464da88ed2df58eb0d000000000000000000272bcb2c4e011f02efc6ce21f381b499d4c7fedfaa26de1390415527780ae7bed3044022004dbcbc8e05c03f710b545395561c0a410433504ef25c2a70c3a55bf59eac5bb02205d219f57f6ae9e4de9a80680647cf1fb7fb0510ae553e33a1f6a4971a4980fc20440fa549a41856c4071dc4a7d8953557f7b91bd696d3edc5343150a9d2fffdc68fe5d74407187f55f0a8df82ce750758d60bdc492438c3c7713f1808d424d89b73045022100d8de457e4f7c28e2c38439fc412cf3f7ecd497b9089d143287fdc1d28d58ee6e02204a63347848e5f2c187ade30f560f2eaf736f43f7a5ef36e9cde9dbbf617c644800000000000000000000000000000000000000000000000000000000000000
decodedInput Invalid continuation byte
encodedInput.slice( 2, 10 ) 38bbfa50

contractName EthereumPot
contractAddress 0x5a13caa82851342e14cd2ad0257707cddb8a31b7
txHash 0x492e1c40d6e8a26bb8b226bb79b815b1a7f6b2a5b17c530912c2f7f938b440b6
receipt.status undefined
encodedInput 0x38bbfa50e6ce11cd8c2e4adb88028c5868da63bddd32fb64905c01c2323369e7561fc336000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000a8d61c48665a7db6211740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c24c50010498c36fc999f7a37ffffe7e4207142d9f708b96f190cfaed75133dba388ac694c2f6db039f926344c918a1d96142a95c332a5403b21e94953a9c75bc27d4290a33044022003bd07a86cb31b9beabbeefa55f9343fdff77afd840da1a43a714948c32e70d1022004f86513ff6689c5553599ccc60da62e063411e484e250545f844a0ba3d1e57ffd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c402449d4602050267dfa4acbe43675e02ac8a477d91bbf33fab46a42c58e95ec00000000000000000a1ec1cdd386d0aafee7de13885b2cee69f3974b0829c0858fcf419e9e9ea609253145022100bc6d73b7b83c37c841dd24aec151d2e359f93fcf3df0882b08597bc95c0bc8d40220620c95117d2695c41aa3ec5a8e83297633d1e50af5d1aef37d4e017aa72c1824041a098edd9f3f8a25940bec7a6a28c23e234000c9e6ca961a2fe739aa8b660cc380b2be58a4050eceb5c1d15f7d849a162e3b542076ba9494beec1857a68e77e83045022100e398782df9507367cf0153f8ec25905e436fea91d72044f19671109b0abef89702206ddedfd01fd84c447b027a15dd00cf64a6b88986e0a6ddb598794bfa9eca5381000000000000000000000000000000000000000000000000000000000000
decodedInput Invalid UTF-8 detected
encodedInput.slice( 2, 10 ) 38bbfa50

What I need is a way to catch the exceptions at the level of the individual parameters, and not at the level of the whole parameter list. The messages themselves are correct. For example if you look here https://etherscan.io/tx/0x492e1c40d6e8a26bb8b226bb79b815b1a7f6b2a5b17c530912c2f7f938b440b6#decodetab there are indeed invalid UTF-8 characters in the string. I need that string, with the invalid characters for my "archeological" investigations please.

$ node -v v10.15.0
$ npm -v 6.4.1
$ uname -a 18.2.0 Darwin K

_decodeLogs error on parsing hex topics

abi-decoder has a dependency: "web3-utils": "^1.2.1".
That caused usage of web3-utils v1.7.3. Now it causes usage of web3-utils v1.7.4.
One of the changes between these versions is a wrapper around BN class added. The earlier version passed the args to the class through, but the new one tries to guess the base by looking "0x" at the beginning of the string.
Since abi-decoder removes "0x" from the value, bn.js tries to parse the value with base 10 and throws an error if the value contains letters or parses it with wrong base if doesn't.

How to decode the contract function name and parameters from a Polygon transaction?

Using this transaction: https://polygonscan.com/tx/0x1b4165c1093936b74803666c75edd720fbd1713b5f77160e3a726299fb04078d

I thought I could simply decode the Input Data to figure out the function name and parameters, so I can call that function directly from Nodejs.

However, it's just returning undefined ๐Ÿค”

const inputData = "0x4ae301550000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b400000000000000000000000000000000000000000000000000000000000000034254430000000000000000000000000000000000000000000000000000000000";

const decodedData = abiDecoder.decodeMethod(inputData);
console.log(decodedData);

Am I using this package incorrectly? Is there any other way to figure out the contract function name and parameters for this transaction?

the abi-decoder.js is missing

I am new to programing but this file is not there at all - there is no actual file named abi-decoder.js ...?
Am I missing something?

Decode a transaction that deploys Smart Contract

Hi there!

I am having issues when I try to decode a transaction which deploys a Smart Contract. Is this feature available or is a problem due to my implementation?

Thanks in advanced.
Regards

Add Ethereum name or address to package.json

I would like to see an Ethereum name or address added to the ethereum field of the package.json file. This will allow consumers of the project to know a cannonical address to send funds to. For example, I'm building an application that will allow developers to automatically donate ETH to all of their npm dependencies that have Ethereum addresses in their package.json files: https://sustainus.io (not quite ready, alpha soon)

Type of arguments

Awesome plugin, thanks so much.

I ran decodeMethod and noticed that it doesn't return the type of each argument that's passed into the function (e.g. uint or address), is there any way to get this data?

Get error logs when tried to decode the following Input for Uniswap-v2 function

Get error logs when tried to decode the following Input:

hash: '0x10949b75c9e65917347feb7df04af16fd2b28d524d600aa924d4f0e3b9362f61'

input:'0x7ff36ab500000000000000000000000000000000000000000000000000000000018ea67400000000000000000000000000000000000000000000000000000000000000800000000000000000000000007850efacf16f2b71a7ba1d8522d93441172b7211000000000000000000000000000000000000000000000000000000006108f08c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000ffc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000ffa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'

functionName: 'swapExactETHForTokens(uint256 amountOutMin, address[] path, address to, uint256 deadline)'
Uniswap-v2 Router addr: '0x7a250d5630b4cf539739df2c5dacb4c659f2488d'

Error:
Error: value out of range (argument="value", value=20, code=INVALID_ARGUMENT, version=bytes/5.7.0) at Logger.makeError (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\logger\src.ts\index.ts:281:20) at Logger.throwArgumentError (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\logger\src.ts\index.ts:285:21) at hexZeroPad (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\bytes\src.ts\index.ts:323:16) at AddressCoder.decode (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\abi\src.ts\coders\address.ts:28:37) at AnonymousCoder.decode (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\abi\src.ts\coders\anonymous.ts:23:27) at D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\abi\src.ts\coders\array.ts:108:31 at Array.forEach (<anonymous>) at unpack (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\abi\src.ts\coders\array.ts:89:12) at ArrayCoder.decode (D:\Workspace\FullStack\defi-lab\backend-blockchain\node_modules\@ethersproject\abi\src.ts\coders\array.ts:233:41) { reason: 'value out of range', code: 'INVALID_ARGUMENT', argument: 'value', value: 20, baseType: 'address', name: undefined, type: 'address' }

Most of other transactions to Uniswap are okay, just a few of them got the above errors.

ab-decoder with Quorum

Does it works with Quorum. Since Quorum is built on top of ethereum it should work.
I tried and none of these two methods decodeMethod & decodeLogs works.

Thanks

ABIEncoderV2 not supported

When trying to use the abi generated for a contract using 'ABIEncoderV2', this library will not throw any exceptions, but instead will behave incorrectly by calculating incorrect method signatures and silently failing to decode transactions. This PR aims to resolve the issue for method calls:

#47

Failed to decode giving BigNumber Error

I was trying to function with different input types, the decoder fails with one of the input and function parameters sequences.

1.To replicate deploy the given contract

contract simple{

uint256 deliveryID;
bytes32[3][] stlFileHash;
string status;

function stringAndUint(string _status,uint256 _deliveryID){
status=_status;
deliveryID=_deliveryID;
}

function stringAndUintAndBytes(bytes32[3][] _stlFileHash,uint256 _deliveryID,string _status){
deliveryID=_deliveryID;
status=_status;
stlFileHash = _stlFileHash;

}

}

2.Use Solidity compiler version on remix: 0.4.18+commit.9cf6e910.Emscripten.clang
3.Input to function stringAndUintAndBytes: [["0x736f6d65","0x736f6d65","0x736f6d65"]],12,"created"

Error:

ethDecoder/node_modules/abi-decoder/node_modules/bignumber.js/bignumber.js:1209
throw error;
BigNumber Error: new BigNumber() not a base 16 number:

Wrong ABI method IDs

Decoder works well for the most of the ABIs, but I got an issue with ABI of this contract.

After adding ABI to decoder it seems that all method IDs are wrong and it is not possible to decode any of the transactions.

For example for swapExactTokensForTokens method it returns 9fe3709a id, while the real method id is f41766d8 (check this transaction for id).

Anybody experiencing this kind of issue? Any workarounds?

How to replicate

import abiDecoder from "abi-decoder";

abiDecoder.addABI(JSON.parse("[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_factory\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_wETH\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0In\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"_tokenIn\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"name\":\"Swap\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"UNSAFE_swapExactTokensForTokens\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"amountADesired\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountBDesired\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountAMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountBMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"addLiquidity\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountB\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"amountTokenDesired\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountTokenMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETHMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"addLiquidityETH\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountToken\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETH\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"factory\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"tokenIn\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenOut\",\"type\":\"address\"}],\"name\":\"getAmountOut\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"}],\"name\":\"getAmountsOut\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"name\":\"getReserves\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"reserveA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"reserveB\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"pair\",\"type\":\"address\"}],\"name\":\"isPair\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"name\":\"pairFor\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"pair\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"amountADesired\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountBDesired\",\"type\":\"uint256\"}],\"name\":\"quoteAddLiquidity\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountB\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"}],\"name\":\"quoteRemoveLiquidity\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountB\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountAMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountBMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"removeLiquidity\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountB\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountTokenMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETHMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"removeLiquidityETH\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountToken\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETH\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountTokenMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETHMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"removeLiquidityETHSupportingFeeOnTransferTokens\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountToken\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETH\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountTokenMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETHMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"approveMax\",\"type\":\"bool\"},{\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"removeLiquidityETHWithPermit\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountToken\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETH\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountTokenMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETHMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"approveMax\",\"type\":\"bool\"},{\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"removeLiquidityETHWithPermitSupportingFeeOnTransferTokens\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountToken\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountETH\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"liquidity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountAMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountBMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"approveMax\",\"type\":\"bool\"},{\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"removeLiquidityWithPermit\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amountA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountB\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"tokenA\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenB\",\"type\":\"address\"}],\"name\":\"sortTokens\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"token0\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1\",\"type\":\"address\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"swapExactETHForTokens\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"swapExactETHForTokensSupportingFeeOnTransferTokens\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"swapExactTokensForETH\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"swapExactTokensForETHSupportingFeeOnTransferTokens\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"swapExactTokensForTokens\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"tokenFrom\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"tokenTo\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"swapExactTokensForTokensSimple\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"amounts\",\"type\":\"uint256[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"stable\",\"type\":\"bool\"}],\"internalType\":\"struct RouterV2.route[]\",\"name\":\"routes\",\"type\":\"tuple[]\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"swapExactTokensForTokensSupportingFeeOnTransferTokens\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wETH\",\"outputs\":[{\"internalType\":\"contract IWETH\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}]"))

console.log(abiDecoder.decodeMethod("0xf41766d80000000000000000000000000000000000000000000001ceea0be01be2f13c00000000000000000000000000000000000000000000000145e1331b613a0e61d800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000007e3c2768b52e765c1fb4365aa1cd099bf908a61a0000000000000000000000000000000000000000000000000000000063ee122f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f4c8e32eadec4bfe97e0f595add0f4450a863a11000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d560000000000000000000000000000000000000000000000000000000000000000"))

data out-of-bounds error

Error on decode trc20 transaction:
0xa9059cbb000000000000000000000000000000000000000000000000000000000d0dacc0
( tron tx id 02108766a3d408b3662eafad8326d72b34e5b0e8d66d226c71d35c2c0099b9e0 )
Error data:
data out-of-bounds (length=32, offset=64, code=BUFFER_OVERRUN, version=abi/5.0.7)

decodeLogs don't work with uint256 tokenId

So i was trying to decode some transactions and got this error :

(node:17304) UnhandledPromiseRejectionWarning: Error: Invalid character
    at assert (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:6:21)
    at parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:274:7)
    at BN._parseBase (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:298:14)
    at BN.init [as _init] (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:105:14)
    at new BN (C:\Users\XX\Documents\DEV\EtherScan\node_modules\bn.js\lib\bn.js:39:12)
    at new BNwrapped (C:\Users\XX\Documents\DEV\EtherScan\node_modules\web3-utils\lib\utils.js:480:16)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:190:30
    at Array.map (<anonymous>)
    at C:\Users\XX\Documents\DEV\EtherScan\node_modules\abi-decoder\index.js:157:21
    at Array.map (<anonymous>)

after some search the cause was this event :

{
  "name": "tokenId",
  "type": "uint256",
  "value": "0xfe4c845b279619589d6c4c444cc9f5d7a5d1d86aec7cb7083fcd58b57cd9b652"
}

i have other tokenId who fail too.

abi-decode can't decode arguments to a constructor

The constructor does not have a name and is therefore not considered by addABI; similarly the input to a create transaction is not prefixed by a hash of the signature of the constructor. So you can't easily decode the arguments to the create transaction.

There is a work around, which is a bit clumsy. First modify the ABI by giving the constructor a name, then prefix the hash of the appropriate signature to the input data, and finally decode will work. I hope that the authors of the decode-abi can come up with a fix that avoids the clumsy work around.

--pieter

Receiving undefined decode input from transacation

Hi, I am trying to decode input from transaction that I receive:

{
  from: '0x1987d1c15d95cab34c154ede0a4c3bf7dba5c287',
  input: '0xa9059cbb0000000000000000000000001987d1c15d95cab34c154ede0a4c3bf7dba5c287000000000000000000000000000000000000000000000000002386f26fc10000',
  to: '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
}

The code looks like:

abiDecoder.addABI(ABI);
const decodedData = abiDecoder.decodeMethod("0xa9059cbb0000000000000000000000001987d1c15d95cab34c154ede0a4c3bf7dba5c287000000000000000000000000000000000000000000000000002386f26fc10000");
console.log(decodedData);

But this is returning undefined.

Any thing that I am missing.

decodeLogs not work for event logs with struct parameter

decodeLogs can not decode events with struct tuple logs, it show empty value.

Environment

$ truffle version
Truffle v5.1.37 (core: 5.1.37)
Solidity - 0.7.1 (solc-js)
Node v10.20.0
Web3.js v1.2.1

Steps to reproduce

  1. get test contract
pragma solidity ^0.7.1;
pragma experimental ABIEncoderV2;
 // SPDX-License-Identifier: MIT
 
 contract SimpleStructStorage {
     struct Data {
         uint a;
         string b;
     }
 
     Data storedData;
 
     event SET(Data d);
     function set(Data memory x) public {
         storedData = x;
         emit SET(x);
     }
 
     function get() public view returns (Data memory x) {
         return storedData;
     }
 }

  1. compile with truffle and run test
const SimpleStructStorage = artifacts.require('SimpleStructStorage')
const Web3 = require('web3');
 
 
contract('SimpleStructStorage', (accounts) => {
   let instance
   const web3 = new Web3('http://localhost:8545');
 
   before('setup', async () => {
     instance = await SimpleStructStorage.new()
     console.log("instance", instance.address);
 
   })
 
   describe('test struct input parameter', () => {
     it('should set struct data', async () => {
       const data = {a: 100, b: "test"}
       const {receipt: {transactionHash}} = await instance.set(data)
       console.log(transactionHash)
       const {a, b} = await instance.get()
       assert.equal(a, 100)
       assert.equal(b, 'test')
 
       web3.eth.getTransactionReceipt(transactionHash, function(e, receipt) {
         const decodedLogs = abiDecoder.decodeLogs(receipt.logs);
         console.log(decodeLogs)
       });
     })
   })
 })

  1. run decodeLogs test script
    node test_abi_decoder.js 0xxxx
//test_abi_decoder.js
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8545');
const {addABI, decodeMethod, decodeLogs}= require('abi-decoder');
 
const abiJson = require('./build/contracts/SimpleStructStorage.json')
const ABI = abiJson.abi
addABI(ABI);
  
const transactionHash=process.argv[2] //you set tx hash
 
 //Input Data
web3.eth.getTransaction(transactionHash, function(e, data) {
   const inputData = data.input;
   const decodedData = decodeMethod(inputData);
   console.log(decodedData.params[0].value);
 });
 
 
 //Event Logs
web3.eth.getTransactionReceipt(transactionHash, function(e, receipt) {
   const decodedLogs = decodeLogs(receipt.logs);
   console.log(decodedLogs[0].events)
 });

Expected behaviour

decodeLogs Should show below output
[ { name: 'd', type: 'tuple', value: [ '100', 'test' ] } ]

Actual behaviour

decodeLogs show empty value
[ { name: 'd', type: 'tuple', value: [] } ]

How to create the testABI

The example of the README.md is fine enough and fully understandable if one knows the solidity code. Still a formal documentation could help (for example I do not understand anonymous events).

But the translation from the solidity code to the Javascript definition of the function types can clearly be done automatically. Surely a script can be written. Has someone written such a script and would be interested in one?

Thank you very much for writing this.
EDIT: Found the solution. It is solc Filename.sol --abi. Should be part of the readme.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.