Hey everyone! I’m working on a smart contract and I’m stuck on how to handle NFT attributes. Here’s what I’m trying to do:
I want to make an endpoint that works with both SFTs and NFTs. The idea is that a user sends two NFTs, and based on their attributes, they might get a new NFT in return. Either way, the user gets their original NFTs back.
I’m wondering if it’s possible to just send the token IDs to the endpoint instead of the whole NFTs. Can the smart contract fetch the NFT info on its own? It seems like a waste of gas to keep sending NFTs back and forth.
Has anyone done something like this before? Any tips or tricks would be super helpful! Thanks in advance!
Sending just token IDs is more efficient. The smart contract can retrieve NFT attributes using the esdt_nft_get_attributes() function, which significantly reduces gas costs compared to transferring entire NFTs. For your endpoint, you might implement a two-step process by first receiving token IDs from the user and then retrieving and processing NFT attributes within the contract. It is important to handle potential errors, including non-existent tokens or insufficient permissions, and to verify that your contract holds the required roles to interact with NFTs. This method should streamline functionality for both SFTs and NFTs.
hey elias, nfts on elrond: u can send token ids only. contract uses esdt_nft_get_attributes() to fetch info, saving gas. make sure to check if nft exists. good luck!
ooh, this sounds like an interesting project!
have you thought about how you’ll handle different types of attributes? like, what if one nft has totally different attributes than another?
im curious - what kind of new nft would users get? is it like… combining traits or something? that could be super cool!
btw, i think the others are right about just sending token ids. wayyyy less gas that way. but how would you make sure the user actually owns those nfts? wouldn’t want someone using tokens they don’t have, right?
anyway, keep us updated on how it goes! i’d love to see what you come up with 