I’m working on an Elrond smart contract and running into a design challenge. I want to build a function that processes Semi-Fungible Tokens and NFTs based on their metadata properties.
The basic flow is that a user provides two NFT tokens, and depending on their specific attributes, the contract either mints a new NFT for them or doesn’t. Either way, the original tokens should stay with the user.
My question is whether I can just pass the token IDs as parameters to my endpoint rather than making users send the actual tokens through a payable function. Can the smart contract look up NFT metadata directly using just the identifier?
It feels like there’s unnecessary overhead and gas costs involved in transferring tokens back and forth when I really just need to read their properties. Is there a more efficient approach for this kind of attribute-based logic?
Yes, you can query NFT metadata directly without any token transfers. Elrond has built-in query methods that let smart contracts grab token info using just the token identifier. I did this last year for a breeding mechanism - instead of making users send their tokens, I used getTokenData inside the contract to pull metadata straight from the blockchain. Way cheaper on gas and no transfer overhead. Just set up your endpoint as non-payable and have it accept token identifiers as parameters. Your contract queries the token properties internally and runs the minting logic based on what it finds. Users keep their original NFTs the whole time, which beats the hell out of transfer-and-return patterns. Plus it’s simpler - users just call one endpoint instead of dealing with ESDT transfers.
there’s a catch most ppl miss - you can query token data, but metadata might not be fully onchain depending on how the NFT was created. if metadata’s stored off-chain (IPFS links), your contract can’t parse the actual attributes directly. you’d need the metadata structure in the token’s properties field during minting. worth double-checking before you go this route.
Nice approach! But I’m curious - have you tested this with large volumes? What happens when your contract checks metadata for dozens of tokens in one call?
Also, how do you handle validation? Users aren’t sending their tokens, so how do you verify they actually own the NFTs they claim to have? Seems like someone could pass random token IDs from other wallets and game your minting logic.
I’ve been thinking there might be a middle ground - maybe require users to sign proof of ownership without the full transfer? Not sure if Elrond supports that natively though.
What attributes are you checking? Simple key-value pairs in token properties or something more complex? Working on something similar and trying to figure out the best metadata structure for contract readability.