I'm currently using transferFrom / safeTransferFrom to transfer the token to another address but I encounter this error.


Error: invalid address (arg="to", coderType="address", value="0x0Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", version=4.0.30)

Upon checking the solidity code of openzeppelin's ERC721.sol the inputs for safeTransferFrom is from, to, tokenId.

 function safeTransferFrom(address from, address to, uint256 tokenId) public {
        safeTransferFrom(from, to, tokenId, "");

Here's the part of code where I perform the transfer web3

const nonce = await web3.eth.getTransactionCount(source)
const contract = new web3.eth.Contract(abi, contractAddress);

const data = await contract.methods.safeTransferFrom(source, destination, 1).encodeABI();

const gasPriceGwei = 3;
const gasLimit = 3000000;
const chainId = 3;
const privateKey = new Buffer.from(addressKey, 'hex')

const rawTransaction = {
  'nonce': `0x${nonce.toString(16)}`,
  'gasPrice': web3.utils.toHex(gasPriceGwei * 1e9),
  'gasLimit': web3.utils.toHex(gasLimit),
  'to': contractAddress,
  'value': '0x00',
  'data': data,
  'chainId': chainId

Additional info, when I change the destination address to contract address it is successfully transferred, but transferred to itself.

  • what does console.log(destination) show and does the destination support ERC721!? – Majd TL Jun 20 '19 at 10:32
  • The destination is the address where I will transfer the token from the source. Yes the they are both eth address and I've tried the transferFrom with success using MyEtherWallet before posting this. – veeps Jun 20 '19 at 12:53
  • is the destination a contract or a normal address? – Majd TL Jun 20 '19 at 12:56
  • if i remember good i think safeTransferFrom check If the target address is a contract that implement onERC721Received – Majd TL Jun 20 '19 at 12:59
  • I tried using transferFrom and it fails when the destination is address but when it is a contract address it is transferred to the contract itself. – veeps Jun 20 '19 at 23:39

Your address is invalid


Assuming the X represents /[0-9a-f]/i then there are too many x's.

  • I redacted my address that's why it was like that. – veeps Jun 20 '19 at 23:37
  • 1
    I cannot be sure if the redacted address is valid. And that is relevant to the question. You may consider using an arbitrary other address rather than a redacted address. – William Entriken Jun 22 '19 at 20:34
  • I think my redacted address is valid cause I tried to create a token using that address and transfer the created token to my other address. I used MyEtherWallet and I am able to transfer it successfully using transferFrom without encountering any error. I will try also your suggestion and will provide more information later. Thanks – veeps Jun 24 '19 at 1:24

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.