Mint

Mint Fractionalize NFTs

We have deployed fractionalizer and are ready to mint some NFTs as a fraction of another one. We will follow these steps:

  • Mint a CIS-2 NFT

  • Transfer NFT to the fractionalizer contract and lock it.

  • Mint fractions

  • Check state

  • Transfer some

  • Burn all of them

  • Check the state

Mint a Regular NFT (To be collateralized)

Remember our fractionalization logic starts with collateralizing the CIS-2 NFT. In order to mint a CIS-2 NFT you can follow this tutorial. As previously mentioned in this tutorial, we will use cis2-multi smart contract for minting our token and you can find the full code here. The screenshot below shows only the mint() function. You can find build/deploy processes in the tutorial.

Let’s check the state by calling the view() function below.

concordium-client contract invoke <YOUR-TOKEN-CONTRACT-INDEX>--entrypoint view --schema ../cis2-multi/dist/schema.bin --grpc-port 10000 --grpc-ip node.testnet.concordium.com

Transfer CIS-2 NFT

Nice. We have successfully minted a CIS-2 NFT and now we can transfer it to the fractionalizer contract. In order to do that, you need to call the transfer() function from the token’s contract using its index and schema file. Create a JSON file to give the input parameters like the below and specify the fractionalizer contract index value.

[
 {
  "token_id": "<YOUR-TOKEN-ID>",
  "amount": "<TOKEN-AMOUNT-TO-LOCK>",
  "from": {
   "Account": [
    "<YOUR-ACCOUNT>"
   ]
  },
  "to": {
   "Contract": [
    {
     "index": <YOUR-FRACTIONALIZER-CONTRACT-INDEX>,
     "subindex": 0
    },
    "onReceivingCIS2"
   ]
  },
  "data": ""
 }
]

Please don't confuse in this part, you need to use the token’s schema to change its state. We want to keep both schemas in the same project folder for the sake of the order. That's why we created a section for the cis2-multi contracts schema file, so you can either copy the schema file from cis2-multi to your fractionalizer directory or you can call it from that file using the JSON above. We will do it the first way, create a file and copy & paste the schema from cis2-multi.

Run the command below to transfer the token to the fractionalizer.

concordium-client contract update <YOUR-TOKEN-CONTRACT-INSTANCE> --entrypoint transfer --parameter-json cis2-fractionalizer/cis2-multi-transfer.json --schema multi/dist/schema.bin --sender <YOUR-ADDRESS> --energy 6000 --grpc-port 10000 --grpc-ip node.testnet.concordium.com

Nice. Let’s check the token contract’s state.

Super cool! As you can see the fractionalizer contract has one token and our account has the rest.

Now, let’s check the fractionalizer’s state.

Even nicer! As you can see, we have locked the “NFT 01” token as received_token_amount with token_id:01 from the cis2-multi contract.

Mint Fractions

We are ready to mint fractions of it now. Create a JSON file like below.

{
 "owner": {
  "Account": ["<YOUR-ACCOUNT>"]
 },
 "tokens": [
  [
   "<YOUR-TOKEN-ID>",
   {
    "metadata": {
     "url": "<METADATA-URL>",
     "hash": "<HASH>"
    },
    "amount": "<FRACTION-AMOUNT>",
    "contract": { "index": <YOUR-TOKEN-CONTRACT-INDEX>, "subindex": 0 },
    "token_id": "<YOUR-TOKEN-ID-COLLATERAL>"
   }
  ]
 ]
}

We need to mint new tokens based on the collateralized one, so specify the exact token_id and contract index. We will specify the amount that sets how many fractions are going to be minted.

concordium-client contract update <YOUR-CONTRACT-INSTANCE> --entrypoint mint --parameter-json ../sample-artifacts/cis2-fractionalizer/mint.json --schema ../cis2-fractionalizer/schema.bin --sender $ACCOUNT --energy 6000 --grpc-port 10000 --grpc-ip node.testnet.concordium.com

Now, let’s check the fractionalizer’s state.

concordium-client contract invoke <YOUR-FRACTIONALIZER-CONTRACT-INDEX> --entrypoint view --schema dist/schema.bin  --grpc-port 10000 --grpc-ip node.testnet.concordium.com

Congrats! You have now locked an NFT and created 1000 fractions that represent the token.

New fraction’s are CIS-2 tokens, you can transfer them or sell them on a marketplace. Anything that can apply to a CIS-2 token is available for these fractions too.

Last updated