0

I am trying to listen to an approval event in an ERC721 token. On approval, I want to call a function.

const approving = new ethers.Contract(gift.address, abi, signer)
await approving.approve(contractAddress, gift.tokenID)
approving.on('Approval', async() => {
      //await some function
})

This was the syntax that I used and I am fairly certain that it worked for a while. Now, however, I get the error: "no matching event (argument="name", value="Approval", code=INVALID_ARGUMENT, version=abi/5.6.4)".

2

1 Answer 1

0

From docs: https://docs.ethers.org/v5/api/providers/provider/#Provider--events

// This filter could also be generated with the Contract or
// Interface API. If address is not specified, any address
// matches and if topics is not specified, any log matches
filter = {
    address: "ADDRESS_OF_NFT_COLLECTION",
    topics: [
        utils.id("Approval(address,address,uint256)")
    ]
}
provider.on(filter, (log, event) => {
    // Emitted whenever approval is given
})

This is cuz Approval event from IERC721 has following arguments:

event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol#L20

Remember that there is also function setApprovalForAll and different event is emitted ApprovalForAll.

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.