1

I want to call the safeTransferFrom function to transfer ERC721 tokens. I am using the following code:

var contract = this.web3.eth.contract(JSON.parse(contractabierc721)).at(contractAddress);
    // console.log(contract);
    var txdata =  contract.safeTransferFrom.call(from, to, 3, function(err, result){
        console.log(result);
    });

The safeTransferFrom signature is from, to , tokenID. However, when I call this way, it gives this error Error: Invalid number of arguments to Solidity function.

What is the correct way to call this function?

I am using web3js version ^0.20.6

0

Your problem is that EIP 721 defines two function with the same name

  • function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
  • function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;

Web3 chooses the first one as default. To execute the other you have indicate the type of the parameters inside brackets. Like this:

contract.safeTransferFrom['address,address,uint256'](from, to, value, function (err, res) {
    console.log(err, res);
})`

With web3 v1.0 it is a similar but function name and parameters, see this for more details: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id12.

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.