Untitled
unknown
plain_text
2 years ago
1.4 kB
5
Indexable
# Define the properties of the NFT maxSupply = 1000 # max number of NFTs that can be created tokenIDToOwner = Map("tokenID_to_owner") # map to store the owner of each NFT tokenIDToURI = Map("tokenID_to_URI") # map to store the URI of each NFT # Mint a new NFT and assign it to an owner def mint(txn, tokenID, owner, uri): # Ensure the token ID does not already exist assert len(tokenIDToOwner.get(txn, tokenID)) == 0, "Token ID already exists" # Ensure the maximum supply has not been reached nftCount = len(tokenIDToOwner.keys(txn)) assert nftCount < maxSupply, "Maximum supply reached" # Assign the NFT to the owner tokenIDToOwner[txn, tokenID] = owner tokenIDToURI[txn, tokenID] = uri # Get the owner of a specific NFT def ownerOf(txn, tokenID): return tokenIDToOwner[txn, tokenID] # Get the URI of a specific NFT def tokenURI(txn, tokenID): return tokenIDToURI[txn, tokenID] # Define the smart contract prog = And( # Check the transaction type is 'ApplicationCall' Txn.Type() == TxnType.ApplicationCall, # Execute the requested function Switch(Txn.ApplicationID(), { # Mint a new NFT [mint]: mint(Txn, Txn.Sender(), Txn.FirstValid(), Txn.Note()), # Get the owner of a specific NFT [ownerOf]: ownerOf(Txn, Txn.FirstValid()), # Get the URI of a specific NFT [tokenURI]: tokenURI(Txn, Txn.FirstValid()) }) ) # Compile the smart contract compiledProg = Teal(prog).compile()
Editor is loading...