JF
josh Furley

Smart Contract U I - Copy this React, Tailwind Component to your project

Ui to use a smart contrac? module nft::NftContract { use sui::tx_context; use sui::object::ID; use sui::transfer; use sui::balance; use sui::event; // Structure to store the NFT collection details struct Collection has key, store { id: ID, // Unique collection ID name: vector<u8>, // Collection name symbol: vector<u8>, // Collection symbol description: vector<u8>, // Collection description creator: address // Creator of the collection } // Structure to store NFT metadata struct NFT has key, store { id: ID, // Unique ID for each NFT name: vector<u8>, // Name of the NFT description: vector<u8>, // Description of the NFT image_url: vector<u8>, // URL pointing to the NFT image owner: address, // Address of the NFT owner collection_id: ID // ID of the collection it belongs to } // Event for minting NFTs struct MintedEvent has store { id: ID, // ID of the minted NFT owner: address, // Address of the NFT owner } // Function to create a new NFT collection public fun create_collection( name: vector<u8>, symbol: vector<u8>, description: vector<u8>, ctx: &mut tx_context::TxContext ): Collection { let creator = tx_context::sender(ctx); let collection_id = tx_context::generate_id(ctx); let new_collection = Collection { id: collection_id, name, symbol, description, creator }; new_collection } // Function to mint a new NFT and associate it with a collection public fun mint_nft( name: vector<u8>, description: vector<u8>, image_url: vector<u8>, collection: &Collection, // Reference to the collection ctx: &mut tx_context::TxContext ): NFT { let owner = tx_context::sender(ctx); let nft_id = tx_context::generate_id(ctx); let new_nft = NFT { id: nft_id, name, description, image_url, owner, collection_id: collection.id // Associate NFT with the collection }; event::emit_event(&MintedEvent { id: nft_id, owner }); new_nft } // Function to transfer NFT ownership public fun transfer_nft( nft: NFT, new_owner: address, ctx: &mut tx_context::TxContext ) { assert!(nft.owner == tx_context::sender(ctx), 1, "Only the owner can transfer this NFT"); transfer::public_transfer_object(new_owner, nft.id); nft.owner = new_owner; } // Function to burn an NFT public fun burn_nft( nft: NFT, ctx: &mut tx_context::TxContext ) { assert!(nft.owner == tx_context::sender(ctx), 1, "Only the owner can burn this NFT"); balance::destroy(nft.id, ctx); } // Function to retrieve NFT metadata, including the collection info public fun get_nft_metadata(nft: &NFT, collection: &Collection): (ID, vector<u8>, vector<u8>, vector<u8>, address, vector<u8>, vector<u8>) { return (nft.id, nft.name, nft.description, nft.image_url, nft.owner, collection.name, collection.symbol); } // Function to get collection details public fun get_collection_details(collection: &Collection): (ID, vector<u8>, vector<u8>, vector<u8>, address) { return (collection.id, collection.name, collection.symbol, collection.description, collection.creator); } }

Prompt
Component Preview

About

SmartContractUI - Create and manage NFT collections with unique IDs, descriptions, and ownership transfer features, built with React and. Copy code today!

Share

Last updated 1 month ago