Example - Mint Function

How to mint the NFT by scanning the chip?

To mint an NFT by scanning the chip, you need to follow these steps:

  1. Add a mint function to your smart contract that will create a new NFT.

function mint(uint NftId) public {
...
} 
  1. Restrict the mint function to be called only by the user who scans the physical BoyoTag. Add the following assert statement as a modifier. Update the mint function with the onlyBoyoRelayer modifier:

modifier onlyBoyoRelayer(){
   require(msg.sender == BoyoLinkRelater,"Must be called by scanning the BoyoTag");
   _();
}
function mint(uint NftId) public onlyBoyoRelayer{
   // see the modifier that this function is using. It will execute the modifier above.
   ...   
   ownerOf[NftId]=tx.origin; // mint the token to who scan the chip
   
   balanceOf[tx.origin]++; // optional: If you storing balance per account.
   totalSupply++; // Optional: increase the totalSupply
   
   emit Transfer(0x0,tx.origin,NftId); // Required by the ERC721 standard
} 
  1. Decide for each BoyoTag what new token ID will be minted when the BoyoTag is scanned for the first time. Add those values to the BoyoTag dashboard linking interface:

  1. Create a pending transaction for that BoyoTag. You can use the Boyo Relayer API or the dashboard. Encode the following Solidity function call: mint(3291). The encoding for this function call should be 0x8492991700000000000000000000000009474, which includes both the function signature and the function parameters.

When user will scan the BoyoTag that is linked to that NFT (that does not exist yet), The BoyoLinkRelayer will forward the data (0x8492991700000000000000000000000009474) to your smart contract and will execute the mint function.

Last updated

Was this helpful?