Accessing NFT metadata in Elrond smart contract without transferring tokens

I’m working on an Elrond smart contract and have a question about the best approach. I want to build a function that takes two NFTs as input, checks their metadata properties, and decides whether to mint a new token based on those properties. The original NFTs should always be returned to the user.

Right now I’m wondering if there’s a way to just pass the token IDs to my contract function instead of making users send the actual NFTs through a payable endpoint. Can a smart contract directly fetch NFT metadata using just the token identifier?

Sending NFTs back and forth seems like it adds unnecessary gas costs and complexity. Is there a more efficient pattern for reading token attributes without requiring token transfers?

Nope, Elrond smart contracts can’t fetch NFT metadata with just token IDs. You need the actual NFT in the contract to access its properties.

I hit this same wall building something similar last year. My workaround was a hybrid setup: users call a view function that validates their NFTs off-chain through API calls, then submit those results with the token IDs to the main contract function. Cuts down on unnecessary transfers but keeps things secure through verification.

You could also try a registry pattern - cache NFT metadata in your contract storage when it’s first used. Later operations just reference the cached data without needing transfers. Only works if you control the NFT collection or know the metadata won’t change though.

Yeah, gas costs matter, but NFT transfers on Elrond are pretty cheap compared to other networks. Sometimes having the actual token there for security and simplicity beats trying to optimize everything.

totally get your frustation! elrond makes it tough to access metadata without the nft. if it’s for your own, storing the data is a smart move, but for external ones, transfers are a must. it really adds up, right? seems like a hassle.

This is a really interesting question! I’ve been thinking about this too. Elrond smart contracts can’t directly query NFT metadata from other collections with just the token ID - they need the actual NFT sent to them to access attributes.

Are these NFTs from your own collection or external ones? If they’re yours, you could store the metadata mappings internally and reference them by token ID without transfers.

Have you considered using Elrond API endpoints to fetch metadata off-chain first, then pass the relevant attributes as parameters to your contract function? Might be more gas efficient than all those back-and-forth transfers.

What metadata properties are you checking? Depending on what you need, there might be some workarounds. Planning to use this for breeding or fusion? Sounds cool!

Gas costs for NFT transfers definitely add up, so I’m curious if anyone else has found good solutions for this :thinking: