I am trying to access an events argument(s) while running tests for my smart contract using node.js/chai. Recently moved to using ethers v6, and the code that works on v5 is no longer valid. Namely:

vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")

const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()

const transactionReceipt = await transactionResponse.wait(1)

subscriptionId = transactionReceipt.events[0].args.subId

Used javascript debug Terminal and I see the contract and the transactionResponse and Receipt but I don't see the events objects in transactionReceipt as I did with ethers v5.

Trying to figure out what I am doing wrong or what the correct method is for ethers v6 but I am struggling.

I have tried to read the ethers v6 documentation but struggling to get an answer from it (newbie and reading documentation is something I am still working on). Any help is most welcome.

Thank you

3 Answers 3


In the transactionReceipt, the logs property contains an array of log objects emitted during the transaction. Each log object has a topics property that holds an array of topic values. The topic value you need should be at index 1 of the topics array.

Try to the change code like this:

    vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer);
            const transaction = await vrfCoordinatorV2Mock.createSubscription()
            const transactionReceipt = await transaction.wait(1)
            subscriptionId = BigInt(transactionReceipt.logs[0].topics[1])

I encountered the same issue while writing code since I was using TypeScript. I think the problem is not with ethers.js cause they provide an events property that only available on a ContractReceipt you can check here.

But the transactionReceipt here is of type ContractTransactionReceipt as returned by createSubscription() function.

So events property do not exist on type ContractTransactionReceipt, I think ChainLink must update their documentation, to get the subscription id.


does this work for you?

let abi = "event Transfer(address to, uint amt)"
let iface = new Interface(abi);
let events = transactionReceipt?.logs.filter(e=>iface.parseLog(e)!=null);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.