I'm learning how to listen events in blockchain. So I listened an event Swap on Uniswap V3 and got this result:
{
blockNumber: 15560305,
blockHash: '0x93fc57218eeb84d071e2f2f81d3e410a7e7981c6b53efb73101b4767c8ffe905',
transactionIndex: 178,
removed: false,
address: '0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640',
data: '0x000000000000000000000000000000000000000000000000000000005f5e1000fffffffffffffffffffffffffffffffffffffffffffffffff0858f94155405810000000000000000000000000000000000006728d2d3f2cada59e3cbc98513f5000000000000000000000000000000000000000000000000a8ef31a7a4b0a2530000000000000000000000000000000000000000000000000000000000031b77',
topics: [
'0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67',
'0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45',
'0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45'
],
transactionHash: '0x1980388f4459f1932f2df2f5fe9fd4854eda822deba0f8a7f59fc787f11fab7e',
logIndex: 321
}
As I understand the data like addresses and amounts is encoded in data. So I tried to decode it:
const Web3 = require('web3');
const web3 = new Web3();
const typesArray = [
{type: 'address', name: 'sender'},
{type: 'address', name: 'recipient'},
{type: 'int256', name: 'amount0'},
{type: 'int256', name: 'amount1'},
{type: 'uint160', name: 'sqrtPriceX96'},
{type: 'uint128', name: 'liquidity'},
{type: 'int24', name: 'tick'}
];
const data = '0x000000000000000000000000000000000000000000000000000000005f5e1000fffffffffffffffffffffffffffffffffffffffffffffffff0858f94155405810000000000000000000000000000000000006728d2d3f2cada59e3cbc98513f5000000000000000000000000000000000000000000000000a8ef31a7a4b0a2530000000000000000000000000000000000000000000000000000000000031b77';
const decodedParameters = web3.eth.abi.decodeParameters(typesArray, data);
And I get en error:
reason: 'data out-of-bounds',
code: 'BUFFER_OVERRUN', length: 160,
offset: 192
Is it the right way to decode it? I only used abiDecoder.decodeMethod() for decoding input data from transactions. So I got confused with different ways of encoding/decoding.
This code gives the same error:
const data = '0x000000000000000000000000000000000000000000000000000000005f5e1000fffffffffffffffffffffffffffffffffffffffffffffffff0858f94155405810000000000000000000000000000000000006728d2d3f2cada59e3cbc98513f5000000000000000000000000000000000000000000000000a8ef31a7a4b0a2530000000000000000000000000000000000000000000000000000000000031b77';
topics = ["0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67","0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45","0x00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45"]
const decodedParameters = web3.eth.abi.decodeLog(typesArray, data, topics);