[Ethereum] safeTransferFrom is undefined in buidler test

address.transfererc-721openzeppelinopenzeppelin-contractssolidity

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?

Best Answer

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);