I'm trying to create a functionality where users can send their ERC721 tokens to my smart contract. I want to use the safeTransferFrom method, as it calls onERC721Received
which ensures my system that the contract has received a token.
Now the first problem that I'm facing is that there's two types of ERC721 safeTransferFrom functions. The first one requires a data
parameter, and the second one doesn't. Attempting to call this function from my frontend give this error: ContractMethodDoesNotExistError: Function "safeTransferFrom" on contract "0x932ca55b9ef0b3094e8fa82435b3b4c50d713043" does not exist.
. But as you can see here on etherscan, this function exists twice as mentioned above.
Function in my frontend
async transferERC721(contractAddress) {
const config = await prepareWriteContract({
address: this.formRaffle.tokenContract,
abi: erc721ABI,
functionName: 'safeTransferFrom',
args: [
this.getAddress,
contractAddress,
this.formRaffle.tokenId
]
})
console.log(config)
const data = await writeContract(config);
console.log("transferERC721 data", data)
},
The second problem which I'm facing is that some ERC721 contracts, such as Cryptopunks don't have a safeTransferFrom
function. (https://etherscan.io/address/0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb#writeContract). This would be another reason why my function for transfering the NFT wouldn't work.
How would I implement a function where a user can transfer their ERC721 to my smart contract, and have the smart contract update it's state whenever this token gets received.