Created
February 4, 2023 02:59
-
-
Save floatbeta/724fb64a204a8cdeff122a19cf40857f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Non-fungible token mint smart contract | |
-- constants | |
local tokenName = "Non-fungible Token" | |
local tokenDescription = "Non-fungible Token is a unique digital asset on the blockchain. It can be used for various purposes such as digital collectibles, gaming, and more." | |
-- state variables | |
local tokenURI = {} | |
local tokenOwners = {} | |
local tokenMetadata = {} | |
-- function to mint a non-fungible token | |
function mint(metadata, URI) | |
-- check if the msg.sender is the owner of the contract | |
if msg.sender ~= address then | |
return false | |
end | |
-- generate a unique token ID | |
local tokenID = sha3(block.timestamp, metadata, URI) | |
-- set the token metadata and URI | |
tokenMetadata[tokenID] = metadata | |
tokenURI[tokenID] = URI | |
tokenOwners[tokenID] = msg.sender | |
return tokenID | |
end | |
-- function to transfer a non-fungible token | |
function transfer(tokenID, to) | |
-- check if the msg.sender is the owner of the token | |
if tokenOwners[tokenID] ~= msg.sender then | |
return false | |
end | |
-- transfer the token to the new owner | |
tokenOwners[tokenID] = to | |
return true | |
end | |
-- function to get the token metadata | |
function tokenMetadata(tokenID) | |
return tokenMetadata[tokenID] | |
end | |
-- function to get the token URI | |
function tokenURI(tokenID) | |
return tokenURI[tokenID] | |
end | |
-- function to get the token owner | |
function tokenOwner(tokenID) | |
return tokenOwners[tokenID] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment