Burn and Unlock

This tutorial will guide you through unlocking and burning fractions of NFTs in Concordium contracts, demonstrating how to transfer and manipulate token ownership, and verifying state changes.

Step 1: Burn Fractions

To unlock the token, you'll burn fractions. The transfer function differs slightly from regular cis-2 multi contracts; it checks if a token transfers back to the same contract, indicating a burn.

Note the following:

  • Start with 1000 tokens in your state, all owned by you.

  • Burn 400 tokens to test properly.

  • Transfer some tokens to another account.

  • Burn the remaining tokens from both accounts.

  • Check the state.

  1. To transfer the tokens, create a JSON file and add the following to the file:

// burn-20.json
[
    {
        "token_id": "<FRACTION-ID>",
        "amount": 400,
        "from": {
            "Account": [
                "<YOUR-ADDRESS>"
            ]
        },
        "to": {
            "Contract": [
                {
                    "index": <FRACTIONALIZER-CONTRACT-INDEX>,
                    "subindex": 0
                },
                ""
            ]
        },
        "data": ""
    }
]
  1. Run the following command:

concordium-client contract update <YOUR-CONTRACT-INSTANCE> --entrypoint transfer --parameter-json cis2-fractionalizer/burn-20.json --schema dist/schema.bin --sender <YOUR-ADDRESS> --energy 6000 --grpc-port 10000 --grpc-ip node.testnet.concordium.com
  1. Check the state now that you've made a change:

You have successfully burned 400 fractions, and the account has 600 left.

Step 2: Transfer to Another Person

Let's transfer some tokens to an actual account for deeper testing. To do this, follow the steps below:

  1. Modify the "cis2-multi-transfer.json" file or create a JSON file named "transfer-account.json."

  2. Transfer 100 fractions to the second account.

Use the following code:

// transfer-account.json
[
    {
        "token_id": "<FRACTION-ID>",
        "amount": 100,
        "from": {
            "Account": [
                "<YOUR-ADDRESS-FROM>"
            ]
        },
        "to": {
            "Account": [
                "<YOUR-ADDRESS-TO>"
            ]
        },
        "data": ""
    }
]
  1. Run the transfer command below:

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

When you run the command, you'll see the following in your terminal:

  1. Recheck the state, and you should see two owners with balances of 500 and 100:

Both of the accounts have some assets now

Step 3: Burn Remaining Tokens

Burn all tokens from both accounts and check the state of the fractionalizer and the collateralized token.

  1. Burn 500 tokens from the first account:

  1. Burn the remaining 100 tokens from the second account to unlock the first asset. You should see your account possessing it in the token's state:

Don’t forget to invoke the function from the second account as it's the owner of the assets.

Step 4: Check the Token Contract State

Check the token contract state to ensure all tokens are returned when burned. In the previous steps, you saw that the account has "999" tokens and the fractionalizer contract has "1" token.

However, your smart contract is designed to transfer the tokens back when they are all burned. So there should be 1000 tokens in the primary account intact:

By looking at the state, you can confirm the following:

  • The primary account received all tokens back.

  • The fractionalizer contract for zero balance

Congratulations, you have completed this tutorial!

Last updated