How to change NFT ownership using ERC721 standard?

I’m working on a project where I need to transfer an NFT (ERC721 token) to a different wallet. I’m using the Mumbai Test Network and the ethers library.

To do this, I think I need to create a contract instance using the ERC721 ABI. However, I can’t seem to find the standard ABI for ERC721 tokens.

For ERC20 tokens, I was able to find the ABI easily and use it like this:

function makeERC20Contract(address) {
  const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
  const userSigner = web3Provider.getSigner();
  return new ethers.Contract(address, ERC20_ABI, userSigner);
}

This works fine for ERC20 tokens, but I’m stuck when it comes to ERC721. Does anyone know where I can find the ERC721 ABI or how to create the contract instance for NFT transfers? Any help would be much appreciated!

hey creativePainter45! i’m fascinated by your nft project :blush: have you tried looking into openzeppelin? they’ve got a ton of helpful stuff for erc721. i think they might have the abi you’re looking for.

what kind of nfts are you working with? i’m super curious about your project! :art:

as for the contract instance, couldn’t you do something similar to your erc20 example, just swapping out the abi? like:

function makeERC721Contract(address) {
  const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
  const userSigner = web3Provider.getSigner();
  return new ethers.Contract(address, ERC721_ABI, userSigner);
}

just a thought! let me know if that helps or if you need more ideas. and seriously, i’d love to hear more about your nft project if you’re willing to share!

yo creativePainter45, for ERC721 stuff, check out OpenZeppelin’s github. they got the ABI you need. once you got that, just swap it in ur code like:

function makeERC721Contract(address) {
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const signer = provider.getSigner();
  return new ethers.Contract(address, ERC721_ABI, signer);
}

them use transferFrom or safeTransferFrom to move ur NFT. good luck with ur project!

Regarding your ERC721 transfer query, you’re on the right track. The OpenZeppelin library is indeed a reliable source for standardized smart contract implementations, including ERC721. You can find their ERC721 ABI in their GitHub repository.

For creating the contract instance, your approach is correct. Once you have the ABI, you can use it similarly to your ERC20 example:

function makeERC721Contract(address) {
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const signer = provider.getSigner();
  return new ethers.Contract(address, ERC721_ABI, signer);
}

After creating the contract instance, you can call the ‘transferFrom’ or ‘safeTransferFrom’ function to transfer the NFT. Remember to handle any potential errors and ensure you have the necessary permissions to transfer the token.