DEV Community

Cover image for Calling overridden functions with Hardhat
ilija
ilija

Posted on

Calling overridden functions with Hardhat

Often when we write tests for our smart contract functions we will use syntax:

await name_of_contract.name_of_function(arg1, arg2, arg3)

Where name_of_contract is the return value of smart contract deployment. Where name_of_function is an example function from smart contract we are testing.

Now, if we want to call the safeTransferFrom function which is often marked as override & virtual in our smart contract (or any similar function) then we will need to use totally different syntax or error safeTransferFrom is not a function will be thrown.

That is why to avoid this problem entarily for any override & virtual we should use syntax:

await name_of_contract["safeTRansferFrom(address,address,uint256)"](
owner.address,
bob.address,
tokenId
);

Now safeTransferFrom will be seen by Hardhat and you will get expected return values.

Top comments (0)