Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active March 15, 2023 04:22
Show Gist options
  • Save mattdesl/c1eff283039b73a093c7777d11248a72 to your computer and use it in GitHub Desktop.
Save mattdesl/c1eff283039b73a093c7777d11248a72 to your computer and use it in GitHub Desktop.
pseudocode for a Non-Fungible Token smart contract (see ERC721 https://eips.ethereum.org/EIPS/eip-721)
// Global Token ID counter
Counter = 0
// Mapping from Token ID to user wallet address
Database = Map<int, address>{}
// Mint/create a NFT and assign it to a new wallet address
function CreateToken (ownerAddress) {
// Limit so that only specific addresses can query this function
// i.e. only the Artist can mint new tokens of this type
if (Query.address != Distributor) throw "Only the Distributor can create a new Token"
// Get a unique ID for the Token and increment global Counter
id = Counter
Counter += 1
// Assign the unique Token ID to its new owner
Database[id] = ownerAddress
}
// Query the wallet address that currently owns the specified Token ID
function OwnerOf (id) {
return Database[id]
}
// Allow owner to transfer their token (NFT) from one wallet to another
function TransferToken (id, newOwnerAddress) {
// Limit so that only the owner of that token can query this function
if (Query.address != Database[id]) throw "Only the current Token Owner can transfer their Token"
// Assign the Token ID to its new wallet address
Database[id] = newOwnerAddress
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment