0

web3.eth.abi.decodeLog([{

type: 'string',
name: 'myString'

} , {

type: 'uint256',
name: 'myNumber',
indexed: true

},{

type: 'uint8',
name: 'mySmallNumber',
indexed: true

}], '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000748656c6c6f252100000000000000000000000000000000000000000000000000', ['0x000000000000000000000000000000000000000000000000000000000000f310', '0x0000000000000000000000000000000000000000000000000000000000000010']);

Result { '0': 'Hello%!', '1': '62224', '2': '16', myString: 'Hello%!', myNumber: '62224', mySmallNumber: '16' }

this is decodelog example in "https://web3js.readthedocs.io/en/v1.2.0/web3-eth-abi.html#decodelog" but i don't know how to find "inputs" parameters.

Thanks for reading

1

1 Answer 1

3

inputs parameter is json object of your event parameters from the smart contract. For example Chainlink contract transfer event is event Transfer(address indexed from, address indexed to, uint256 value);. Now if we want to decode this event the input parameter will look like this:

[{
    type: 'address',
    name: 'from',
    indexed: true
},{
    type: 'address',
    name: 'to',
    indexed: true
},{
    type: 'uint256',
    name: 'value'
}]

Now in order to fully decode the event log we need the rest two parameters which are hexString and topics. Let's take for example this random transaction and use it event log data. Example:

web3.eth.abi.decodeLog([{
    type: 'address',
    name: 'from',
    indexed: true
},{
    type: 'address',
    name: 'to',
    indexed: true
},{
    type: 'uint256',
    name: 'value'
}],
'0000000000000000000000000000000000000000000000041b9ece2305db9c00',
['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x00000000000000000000000059a5208b32e627891c389ebafc644145224006e8', '0x0000000000000000000000004e2e464420f1392ba08282644feba1bf650e1cc6']);

When you execute this code you will see what values have been passed and saved for this event log.

1
  • 1
    how can I get event name from transaction receipt event logs? Feb 11, 2020 at 8:35

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.