0

I have deployed a smart contract that inherits ERC721EnumerableUpgradeable which inherits ERC721Upgradeable.

When I deploy using Remix, for example, I see the function safeTransferFrom, which is a function of the contract ERC721Upgradeable, despite I have just deployed my main contract, and all the methods that are public from inherited smart contracts are already there for me:

enter image description here

But when I use Hardhat and I want to test that same function, it seems that the ERC721Upgradeable contract is not being recognized, because I am getting the following error:

TypeError: smartVault.safeTransferFrom is not a function

The test I am running is this one:

  it("Owner should be able to transfer smart NFT", async function () {
    const { smartVault, owner, otherAccount } = await loadFixture(deploySmartVault);
    await smartVault.safeTransferFrom(owner.address, otherAccount.address, 0);
  });

How can I get to interact with that function using Hardhat?

1 Answer 1

5

The problem was that safeTransferFrom is a overloaded function. Overloaded functions are functions that are defined more than once, with the same name, but they take different types and/or number of arguments.

In ethers.js (which is the library that Hardhat uses under the hood), the syntax to call an overloaded contract function is different from the syntax to call a non-overloaded function.

Overloaded functions need to be called by specifying the function signature.

From the ethers.js docs:

// ethers
const abi = [
  "function getMessage(string) public view returns (string)",
  "function getMessage() public view returns (string)"
]
const contract = new ethers.Contract(address, abi, signer);

// for ambiguous functions (two functions with the same
// name), the signature must also be specified
message = await contract['getMessage(string)']('nice');

So for the example in the question:

Wrong:

contract.safeTransferFrom(addr1, addr2, 1);

Correct:

contract["safeTransferFrom(address,address,uint256)"](addr1, addr2, 1);

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.