I’m new to Near Protocol and Rust and I’m trying to recreate my NFT app that links string values (IPFS hashes) to token IDs. I’ve done this before with Solidity on Ethereum but I’m stuck with Near.
I’m using the NFT template from the Near dev site. I added a string mapping for ‘sketch’ collections to hold IPFS hash values. These will be used as image sources on the front-end later.
Here’s what I’m trying to do:
Map string values to a token ID and owner ID
Create a function to mint tokens with custom IDs
Allow only the contract owner to mint tokens
Implement a transfer function
Is my approach on the right track? I’m not sure if I’m using the Near Protocol features correctly. Any tips or suggestions would be super helpful!
I’d really appreciate some guidance on how to structure this properly in Rust for Near Protocol. Thanks!
I’ve worked on a similar project with Near Protocol and can share some insights. For mapping string values to token IDs, you’ll want to use Near’s persistent collections like UnorderedMap. These are more gas-efficient than standard Rust collections.
For minting with custom IDs, you can modify the mint function in the NFT standard to accept a token ID parameter. Just be careful to check for ID conflicts.
Restricting minting to the contract owner is straightforward - use the #[payable] attribute on your mint function and check msg.sender against the contract owner.
For transfers, the NFT standard already includes a transfer function, so you shouldn’t need to implement your own unless you have specific requirements.
One tip: use near_sdk::env::log to emit events for important actions. This helps with indexing and front-end integration later on.
Hope this helps point you in the right direction! Let me know if you need any clarification on implementation details.
hey kai, i’ve done smthin similar. use UnorderedMap for the ipfs hash mapping. for custom IDs, just tweak the mint function. owner-only minting is easy - use #[payable] and check msg.sender. transfers are already in the nft standard. good luck with ur project!