I'm listening on a contract with
contract.on('EventName', async (arg) => {
doSomething(arg)
});
Is it possible to retrieve more info about the transaction where the event was emitted, like the hash?
I tried something like:
contract.on('EventName', async (transactionHash, arg) => {
console.log(transactionHash);
doSomething()
});
With that, the program crashes but I can see the infos I want in the stack trace. However, how can I access them in the correct way?
The args of the Listener function are in the following fashion:
contract.on('EventName', async (arg1, arg2, ..., argLast, event) => {
console.log(event.transactionHash);
});
If you are not sure how many args gonna be, you can do a generalised way:
contract.on('EventName', async (...args) => {
console.log(args[args.length - 1].transactionHash);
});
@zemse Many thanks. That was exactly what I was searching for. This issue can be closed.
Most helpful comment
The args of the
Listenerfunction are in the following fashion:If you are not sure how many args gonna be, you can do a generalised way: