Create Non-Transferable tokens (aka Soulbound tokens)

PART 2: Lock/Unlock APIs to create non-transferrable tokens.

Be it Soulbound tokens or tickets on BlockChain, MetaKeep Lock and Unlock Token APIs help you with both use cases. MetaKeep NFT smart contract is designed to support both non-transferable and transferable tokens in the same collection. You can convert a token from non-transferable to transferable and vice-versa with just an API call.

Non-transferrable tokens solve multiple scenarios

  • Issue an educational certificate as an NFT: Education certificates are unique and are not supposed to be transferred to someone else. Using MetaKeep, you can issue the certificate as a locked NFT. The certificate NFT still lives on the blockchain and is owned by the qualified user. The user can use the token to show their qualification but they won't be able to transfer the token to another user.

  • Lock the NFT for some time: Suppose you want to issue an NFT to the user which they shouldn't be able to transfer for a cooling period, or till the time they fulfill certain criteria. You can issue a locked token to the user and later use the unlock token API once the cooling period is over.

Following further, in this tutorial, we will discuss the end-to-end flow for locking and unlocking NFT tokens with MetaKeep’s REST API.

You can find the end-to-end working demo here.

Steps to Lock NFT Token

Step 1: Create a request with the following Parameters

{
  "nft": {
      "collection" : <Address of the Collection>
  },
  "token": {
      <Token Id>
  }
}

Step 2: Make a POST request to the nft/lock API

const options = {
    method: 'POST',
    headers: {
        accept: 'application/json',
        'content-type': 'application/json'
    },
    body: JSON.stringify({
        "nft": {
            "Collection Address"
        },
        "token": "token Id"
    });
};

fetch('https://api.metakeep.xyz/v2/app/nft/lock', options)
    .then(response => response.json())
    .then(response => console.log(response))
    .catch(err => console.error(err));

On successful request, the token will be locked in the smart contract. Any transfer operation on the token will fail.

Steps To unlock token

Step 1: Create a request with the following parameters

{
  "nft": {
      "collection" : <Address of the Collection>
  },
  "token": {
      <Token Id>
  }
}

Step 2: Make a POST request to the nft/unlock API

const options = {
    method: 'POST',
    headers: {
        accept: 'application/json',
        'content-type': 'application/json'
    },
    body: JSON.stringify({
        "nft": {
            "Collection Address"
        },
        "token": "token Id"
    });
};

fetch('https://api.metakeep.xyz/v2/app/nft/unlock', options)
    .then(response => response.json())
    .then(response => console.log(response))
    .catch(err => console.error(err));

On successful request, the token will again be unlocked in the smart contract. Token transfer operation will now be successful.

🚧

Any transfer operation on locked tokens will fail.

If the token is locked, the transfer APIs will fail on the chain.

Running the Demo

You can find the end-to-end working demo here. Follow these steps to get the demo running:

Step 1: Prerequisite

Before proceeding, you need to finish the first part of the tutorial Create your First NFT collection and Mint Tokens. Once you have the collection address and token ID, store it somewhere because we would need that later.

Step 2: Update .env file

Update the .env file with the API key, collection address, and token ID you got in the first step.

Step 2: Run the script

Navigate to the ntfs/scripts directory. Then, run the command:

npm install
npm run lockUnlockToken

The demo will create lock the token, and wait for the transaction mining. Then, it will unlock the token and wait for transaction mining again.

Next Steps

Voila! You have successfully locked and unlocked the NFT token 🎉🎉.

You should now have a good idea about Non-Transferable tokens (aka Soulbound tokens) and how to lock and unlock tokens using MetaKeep infrastructure. In the upcoming tutorial, we will discuss how to transfer NFT tokens from one address to another address(P2P transfer). Last but not least, following that, there will be a small discussion on how to list tokens on OpenSea.