How to read events from a particular transaction?
Closed this issue · 2 comments
Hi,
I need some guidance.
I am looking to read events emitted from a particular transaction.
I have the txHash 0xd34c299bc37b28a33d60382ad61ea5518c445c4a0acad91420a69e7e69a038e8
.
const txReceipt = await caver.klay.getTransactionReceipt(txHash)
I get the receipt as :
{
"blockHash":"0x1d8d7af6023824ea452ab3cd294c86ee642cb08a359a18656bcc706a3a2c942a",
"blockNumber":81767413,
"contractAddress":null,
"from":"0xf192d912649d59d91cd61a141e56e8a0e0a85294",
"gas":"0x1312d00",
"gasPrice":"0x5d21dba00",
"gasUsed":258674,
"input":"0x50bb4e7f000000000000000000000000f192d912649d59d91cd61a141e56e8a0e0a8529400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000004368747470733a2f2f697066732e696f2f697066732f516d4e725a4164357447754c394c586a3751544c4e50645270734b555a4d675270716e4b73394b544a7457744c690000000000000000000000000000000000000000000000000000000000",
"logs":[
{
"address":"0x2ae2e621Ee0152d9B13D5B5AF25EB1c0f091c682",
"topics":[
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000f192d912649d59d91cd61a141e56e8a0e0a85294",
"0x0000000000000000000000000000000000000000000000000000000000000001"
],
"data":"0x",
"blockNumber":81767413,
"transactionHash":"0xd34c299bc37b28a33d60382ad61ea5518c445c4a0acad91420a69e7e69a038e8",
"transactionIndex":0,
"blockHash":"0x1d8d7af6023824ea452ab3cd294c86ee642cb08a359a18656bcc706a3a2c942a",
"logIndex":0,
"id":"log_32ee2989"
}
],
"logsBloom":"0x00000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000400000008000000000000000000040000000000000000000000000000020000000080000004000800000000000000000000000010000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000001000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000",
"nonce":"0x1d",
"senderTxHash":"0xd34c299bc37b28a33d60382ad61ea5518c445c4a0acad91420a69e7e69a038e8",
"signatures":[],
"status":true,
"to":"0x2ae2e621ee0152d9b13d5b5af25eb1c0f091c682",
"transactionHash":"0xd34c299bc37b28a33d60382ad61ea5518c445c4a0acad91420a69e7e69a038e8",
"transactionIndex":0,
"type":"TxTypeSmartContractExecution",
"typeInt":48,
"value":"0x0"
}
I am looking to decode the events from this transaction.
Going through the docs i can find some info on getting events but its not so clear to me how to get the events data directly from tx hash.
myContract.events.eventName([options][, callback])
myContract.events.allEvents([options] [, callback])
myContract.getPastEvents(event [, options] [, callback])
I minted an NFT in KP17 so hoping to read the Transfer event from the tx receipt log.
Any help would be appreciated.
Thank you.
Maybe you can see after sending a transaction through (caver.kct.kip17
or caver.klay.KIP17
), you can see events
field in receipt.
You can see this file.
Those events field is parsed in here.
You can read detail about filter and logs in Klaytn Docs.
Thanks @jimni1222 this seems to be working for me.
const kp17Contract = new caver.klay.Contract(caver.kct.kip17.abi, contractAddress)
const allEvents = await kp17Contract.getPastEvents('allEvents', {
fromBlock: 81767413,
toBlock: 81767413
})