Skip to main content

ERC721 NFT Smart Contract

The meta-transaction smart contract template to manage multiple-copies NFTs. Though their content is identical, each NFT has a different token ID. In a video game, you can sell an NFT and pay for gas in place of the NFT receiver. Within this standard, the token is linked to its owner's address and to the URI (Unique Resource Identifier), which references the NFT content).

The ERC721 is a smart contract standard which is specialised in single-copy Non Fungible Tokens (NFT) and out-of-the-box compatible with Opensea. In an ERC721, every NFT is unique which means you have to reference the content for each NFT.

This version enables you to send transactions on behalf of your users so they can use their NFT without having to pay for gas fees.

It also includes the blacklist feature. It allows the owner to block one or more addresses from transfering tokens on behalf of your users for example if you want to block the sales happening in a marketplace.

Notice that we do not store any content in the smart contract. Smart contract store only references. It is up to smart contract readers to find the content using references.

Starton provides an IPFS integration in case you need to host your NFT content.

caution

To use this contract, you will need to import the etherjs library, create and sign a typeTransaction before you can use the function executeMetadata().

Parameters

  • definitiveName: The name of your smart contract which will be reflected on-chain.
  • definitiveSymbol: The symbol associated with the NFT or its collection.
  • initialBaseTokenUri: Will be used to get the token URI.
    • Using IPFS: ipfs://ipfs/
    • Using a centralised server: https://yourapi.com/endpoint/
  • initialContractUri: The URI of the metadata that will be used to give more details about the description.
  • initialOwnerOrMultisigContract: The address that will own the NFT Collection.

Functions

FunctionInput ParametersDescription
PAUSER_ROLENoneReturns the value of the pauser role.
MINTER_ROLENoneReturns the value of the minter role.
LOCKER_ROLENoneReturns the value of the locker role.
METADATA_ROLENoneReturns the value of the metadata role.
DEFAULT_ADMIN_ROLENoneReturns the address of the admin role.
pauseNoneCalled to pause by address with a pauser role, disables every variable state changes of the contract.
pausedNoneReturns true when the contract is paused. Returns false otherwise.
unpauseNoneCalled to unpause by address with a pauser role.
executeMetaTransaction(address userAddress, bytes memory functionSignature, bytes32 sigR, bytes32 sigS, uint8 sigV)Executes a transaction on behalf of another user by providing their address, the function to call and the signature of the transaction.
getDomainSeparatorNoneReturns the domain separator according to the EIP712.
getChainIdNoneReturns the chain id according to the EIP712.
supportsInterface(bytes4 interfaceID)Returns true if the contract implements the specified interface.
hasRole(bytes32 role, address account)Returns true if the address specified has been granted the role.
getRoleAdmin(bytes32 role)Returns the role that can control the specified role.
grantRole(bytes32 role, address account)Grants a role to the address specified.
revokeRole(bytes32 role, address account)Removes a role from an address.
renounceRole(bytes32 role, address account)Removes a role from an address. The address must be the caller address.
burn(address, uint256 amount)Erases a specified amount of token.
nameNoneReturns the descriptive name of the smart contract.
symbolNoneReturns the symbol set for this contract.
totalSupplyNoneReturns the total amount of tokens.
safeTransferFrom(address from, address to, uint256 tokenId)Returns true when the transfer of the token has been successful to the specified address. Notice that the spender must be either way the owner or have the approval to transfer this token.
safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)Returns true when the transfer of the token has been successful to the specified address. Notice that the spender must be either way the owner or have the approval to transfer this token.
transferFrom(address from, address to, uint256 tokenId)Returns true when the transfer of the token has been successful to the specified address. Notice that the spender must be either way the owner or have the approval to transfer this token. Opposite to sateTransferFrom, it doesn’t check that the to address can receive the token.
approve(address to, uint256 tokenId)Approve the spending of the token to a certain address.
balanceOf(address owner)Returns the amount of tokens owned by the owner.
ownerOf(uint256 tokenId)Returns the address that own the token.
tokenURI(uint256 tokenId)Returns the URI for a token.
getApproved(uint256 tokenId)Returns the address that has been approved to transfer this token.
setApprovalForAll(address operator, bool approved)Set the approval of all tokens owned to a true or false that a operator can transfer.
isApprovedForAll(address owner, address operator)Returns true if the operator can transfer all the tokens owned by owner.
tokenOfOwnerByIndex(address owner, uint256 tokenId)Returns the nth tokens minted by a specified address.
tokenByIndex(uint256 index)Returns the token id of the nth token minted.
contractURINoneReturns a public URL that contains the metadata of the collection
lockMintNoneRevokes the ability to mint. Sender must have the LOCKER_ROLE.
lockMetadataNoneRevokes the ability to change metadata. Sender must have the LOCKER_ROLE.
mint(address to, string memory uri)Mint a new token with the given URI.
setContractURI(string memory newContractURI)Change the contract URI to a new URI.
setBaseTokenURI(string memory newBaseTokenURI)Change the base token URI to a new URI.
  • Parameters
  • Functions