I’m working on a smart contract that needs to transfer NFTs but I’m stuck on finding the correct tokenID. I have some CryptoHorses NFTs that I want to move using my contract but I can’t figure out how to get the tokenID that’s needed for the transfer functions.
My contract works fine for regular token transfers on different networks like Polygon and Avalanche. But when I try to transfer NFTs, both transferFrom() and safeTransferFrom() need a tokenID parameter. I’m not sure how to get this ID from the NFT itself.
Does anyone know the proper way to identify the tokenID from an NFT so I can use it in my transfer functions? Any help would be great.
u can check the NFT contract on Etherscan or Polygonscan for the ids. if u own the NFTs, try tokenOfOwnerByIndex() with ur wallet address to get the IDs. most contracts have this function. good luck!
This is a super common issue! What’s your setup like - are you transferring NFTs you already own, or building something to handle random NFTs?
TokenIDs can be a pain depending on your approach. If you’ve got CryptoHorses in your wallet already, you can grab the tokenIDs from the contract interface or check OpenSea/PolygonScan. But maybe you’re trying to find them programmatically?
Couple questions to help out:
- Transferring all NFTs from a collection or just specific ones?
- Do you already have the tokenIDs or does your contract need to find them dynamically?
- Calling these functions from your smart contract or from frontend/script?
Really depends what you’re building. Batch transfer tool? You’d enumerate tokens owned by an address. More targeted transfers? Totally different strategy.
What’s your end goal here? That’d help point you the right way!