7

I have started using buidler for testing/compiling my contracts. In one test i have setup a scenario that a owner attempts to transfer a token to another wallet address.

My contract is inheriting from the Open Zeppelin ERC721.sol one. When trying to call token.safeTransferFrom(args) it says that safeTransferFrom is not a a function and when logging it out it shows as undefined.

Im pretty new to solidity and smart contract coding but looking through the source I can see that the function declaration looks the same as approve which I can call quite happily using token.approve(args).

Is there anything obvious that Im missing?

3
  • Can you find safeTransferFrom function in the contract ABI? Aug 27, 2020 at 12:03
  • @ChenchenYo Yes I can see it in there
    – Sam Mason
    Aug 27, 2020 at 22:15
  • What's your code? Maybe token is not properly initialized.
    – Ismael
    Aug 27, 2020 at 22:54

1 Answer 1

10

Ran into this myself as well. Are you using ethers.js with Buidler?

The safeTransferFrom method is overloaded and generally with ethers.js the bare definition is the default method used.

If you run console.log( Object.keys(token) ) you'll see the methods on the token and you'll likely see two definitions of safeTransferFrom. Pick the one you want to use then you can call it like this:

token['safeTransferFrom(address,address,uint256)'](fromAddr, toAddr, tokenId);
1
  • 2
    Thank you Dan-Nolan. if using a different caller: await token.connect(user1)['safeTransferFrom(address,address,uint256)'](userX, userY, 1);
    – Russo
    Feb 16, 2021 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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