2

I have openzeppelin's standard ERC721 contract.

Below is the helper function that returns bytes data that will be used for some purpose.

async function getErc721SafeTransferFromTransaction(tokenInstance, args) {
    const txData = tokenInstance.interface.encodeFunctionData("safeTransferFrom",args);
    return txData;
  }

When I call that function with deployed ERC721 instance and [from,to,tokenId] as an argument, I get the following error.


     Error: multiple matching functions (argument="name", value="safeTransferFrom", code=INVALID_ARGUMENT, version=abi/5.6.4)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
      at Logger.throwArgumentError (node_modules/@ethersproject/logger/src.ts/index.ts:277:21)
      at Interface.getFunction (node_modules/@ethersproject/abi/src.ts/interface.ts:210:24)
      at Interface.encodeFunctionData (node_modules/@ethersproject/abi/src.ts/interface.ts:373:37)
      at getErc721SafeTransferFromTransaction (test/utils/helper.js:30:44)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at runNextTicks (node:internal/process/task_queues:64:3)
      at listOnTimeout (node:internal/timers:533:9)
      at processTimers (node:internal/timers:507:7)

Seems like ethers.js is having issue is with safeTransferFrom as openzeppelin's standard ERC721 has overloaded safeTransferFrom method, one with data argument and one without. How can I solve this and get the encoded data?

1 Answer 1

2

You are missing the parameters, as it got 2 function with the same name but with different parameter lengths.

  1. in case you want to call without data.
const txData = tokenInstance.interface.encodeFunctionData("safeTransferFrom(address, address, uint256)",args);
  1. in case you want to call with data.
const txData = tokenInstance.interface.encodeFunctionData("safeTransferFrom(address, address, uint256, bytes)",args);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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