# Learn how to code your own SoulBound NFT Smart Contract

By [BuildBear](https://paragraph.com/@buildbear-3) · 2023-07-25

---

Before writing our SoulBound contract, let us understand what SoulBound NFT is and how is it useful to us.

**_Soulbound Tokens (SBT) are just non-fungible tokens (NFTs) that, “once picked up, cannot be transferred or sold to anyone else.”_**

Soulbound tokens can help you:

*   create an openly verifiable system where people can issue their **digital resume** as SoulBound tokens which will help verifying an individual’s work histories and removes falsification.
    
*   make it possible for protocols to verify borrowers’ credit profiles assess their credit scores to determine how much they can obtain in loan.
    
*   can help issue educational certificates like driver’s license, certificates of incorporation, and other core personal and professional proofs.
    

_and many more_

Ideas where you can use SoulBound Tokens:

*   In your college, right now, for adding test scores
    
*   Using as an identification token in your college
    
*   Using Soulbound token as your Resume
    

Thus, lets not wait anymore and start with our Day 3 ⚒️

**1\. Create a project and install dependencies**
-------------------------------------------------

1.1: Use the following commands on your CLI to initialize your project.

mkdir soulbound-NFT-with-buildbear && cd soulbound-NFT--with-buildbear

1.2: Run the command `npx hardhat` on your CLI and choose `Create a Javascript Object`; choose `yes` for all the options.

Once you have successfully executed the above and if you were to open this repo in VS Code, you should have a directory structure, similar to the following:

![](https://storage.googleapis.com/papyrus_images/c299c7eb2ccb076c1a7debd0b58edc2a04ef4d01a93141d6b99625436a13556c.png)

**2\. Coding your Soulbound NFT contract**
------------------------------------------

2.1: Create a file named `Soulbound.sol` in the `contracts` folder.

2.2 We have used the code of ERC-721 contract which we have already learnt in [_Dude! I just deployed my own NFT!!! ….WT.F!_](https://medium.com/buildbear/dude-i-just-deployed-my-own-nft-wt-f-9ef91c778af)

You can use the following code:

![](https://storage.googleapis.com/papyrus_images/29874d179df7cff2b2dab494e1f0539727912bdfdf157d8f5dcc67363d6507e7.png)

You can even get the above code from our Github over [_here_](https://github.com/BuildBearLabs/Tutorials/tree/main/soulbound-NFT-with-BuildBear)

**3\. Deployment and Testing why SoulBound Tokens are different**
-----------------------------------------------------------------

Now, let us deploy it on private testnet using BuildBear to play around with the contract

3.1: Creating a Private Testnet on BuildBear 🐻‍❄️ \*(why BuildBear, you ask? Have a look over here: \*\*[**_Where Localhost Fails_**](https://medium.com/p/492f1038883d) and \*[**Win Web3 Hackathons, using BuildBear Testnet’s analytics**](https://medium.com/p/e67656093f9d)**_)_**

3.1.1: Visit the [_BuildBear App_](https://home.buildbear.io/). Once you login with your Github account, you will see a page similar to the image added below

![](https://storage.googleapis.com/papyrus_images/535454352e4ef5b77bed44b2237272bc62ee37d14ddedd22eec69a7f4e8603ca.png)

Here we have to create a simple node for our staking application so we will click on the **create an endpoint a**nd we will be redirected to the node configuration page. But for this article, we will be using the default configuration for creating our node.

So we will simply click on the `create` button as shown below.

![](https://storage.googleapis.com/papyrus_images/3490a53725d6a345bae694f79b4906997b3cee09bf3c3587fd09b4137022af8a.png)

Congratulations! You have created your private testnet node!

Your page should be updated to something similar to the following:

![](https://storage.googleapis.com/papyrus_images/a1109263307326b563786fb95fcdfb00b3457c47e7f9791c79fe1cfd2c19f090.png)

Click on the RPC URL (either copy of click to view) to get the RPC to your private testnet.

3.2: In order to perform transactions, we need funds from faucet. Don’t worry! We don’t have to find random faucets to get test ether.

Click on the **Open Faucet** option and add your choose your account.

![](https://storage.googleapis.com/papyrus_images/379d7c440119f12c0c10efc76ce1a7104d3fcac0a343fd3e565346e5dfa15426.png)

After that, click on the **Add to Metamask** option in the right corner of the faucet page.

Your metamask would be provided with 1,000 BB ETH immediately.

3.3: Update the`hardhat.config.js` to the following:

![](https://storage.googleapis.com/papyrus_images/9f6029c02d486a4c17375df6689042977fb545f89496c77accbbddd0a2f82d54.png)

In the networks, we have created a network called **buildbear** and added our RPC URL there and then added the private key of the metamask account (please do not expose your private key to anyone, ever).

Now our config is ready! Let’s write our smart contract.

**4\. Deploy our Soulbound Contract using BuildBear**
-----------------------------------------------------

4.1: Use the following script to deploy your souolbound contract:

    const { ethers } = require("hardhat");
    const hre = require("hardhat");async function main() {
      const Soulbound = await hre.ethers.getContractFactory("Soulbound");
      const soulbound = await Staking.deploy();  await soulbound.deployed();  console.log(
        "Soulbound contract deployed to:", soulbound.address
      );
    }main().catch((error) => {
      console.error(error);
      process.exitCode = 1;
    });
    

Open your CLI and run the following command:

    npx hardhat run scripts/deploy.js --network buildbear
    

4.2 Now if you go back to the BuildBear Explorer (link available from the [_BuildBear App_](https://home.buildbear.io/), once you have created your private testnet). You will see your deployed contract.

![](https://storage.googleapis.com/papyrus_images/dc80de815c80884aef3852fd665fa8d137cbd86cb6d4c80a97c9e38d27340d9a.png)

4.3 Now open your deployed address and open the **write contract** tab under the **contracts** tab

![](https://storage.googleapis.com/papyrus_images/5c30a03a44e6097afc9a657568e7ae53c6d154666546589ce030f9256a4add74.png)

You can see here we have all the functions which we have included in our contract.

To mint our soulbound token, we are going to call the **safeMint** function which requires the address of the user and the tokenURI of the NFT which includes all the metadata of the token.

4.4 _(optional):_ If you’re not aware of how to upload tokenURI on IPFS then you must follow along.

IPFS allows you to store your data like images, and other data on the blockchain. In order to store your own data, open Pinata which is a platform that provides you to store data on IPFS.

Create a file .json file on your system and add the following data to it.

    {
        "title": "John Doe",
        "type": "Identity Card",
        "properties": {
            "age": {
                "type": "string",
                "description": "19"
            },
            "image": {
                "type": "string",
                "description": "hhttps://gateway.pinata.cloud/ipfs/QmQPo8X32C1NnpqjwckxyAHpmXyoJk1G1x4fu5GLcxLqVG"
            }, 
            "course": {
                "type": "string",
                "description": "Computer Science"
            }
        }
    }
    

And upload this file on Pinata. This will provide you with an IPFS link where the metadata is stored.

Use that link to mint your NFT token.

4.5 Pass your wallet address and tokenURI to the **safeMint** function to mint your Soulbound token.

![](https://storage.googleapis.com/papyrus_images/be6c0d448a2658362bc0a418d5d4eda01dae5372dfa807dcbb1ab43f402acb97.png)

And click the **write** button.

You can now see that our Soulbound token is minted. Use the transaction hash provided to see the token information.

![](https://storage.googleapis.com/papyrus_images/5229f203215efc48eb76ebee91213c50037a1be9eaea145e7dbe5dae726a62dc.png)

Here you can see in the **token transferred,** we got _ERC721 Transfer found_

4.6 If you’ll see the **advanced** tab, you can see the token has been minted at the address provided by the user.

![](https://storage.googleapis.com/papyrus_images/55bc85e5a83b8a67254f35329e5f278e6c3185a6dab61ec2da5c6323028de89c.png)

You can use the URI value and search it on your browser, you will receive the metadata of your token, which you just provided.

![](https://storage.googleapis.com/papyrus_images/670934d5495e1d9308a9cb0128046c5dbc7f18ff939ced3c350d1f9139209a9b.png)

> _USP of SoulBond Tokens. This is what makes SoulBond the “SoulBond”_

Soulbound tokens are majorly used as identification tokens which can only have one owner.

But even in the identification tokens, we might need to update any new data to it. So for that, we are not going to mint a new token, instead update the metadata of the same token.

Let us understand how we can update the metadata of the minted token.

4.7 Open Pinata and click on the edit metadata option and add the key value pair you want to add to the metadata.

![](https://storage.googleapis.com/papyrus_images/916ae3ae09eec421d3d3fe0d662bc2e8746940a1691aab0944e3ab49b8d9bb0f.png)

This will add the above key-value pair to your metadata in some time and you don’t need to mint another token to add the metadata 😃

Soulbounds tokens are not just simple NFTs but have their own advantages which makes it so attractive.

To learn more about BuildBear, read here [_docs_](https://docs.buildbear.io/docs/intro)

Get the above Github code from [_here_](https://github.com/BuildBearLabs/Tutorials/tree/main/soulbound-NFT-with-BuildBear)

If you appreciate what we are doing, please follow us on [_Twitter_](https://twitter.com/_BuildBear) and [_Join the Telegram_](https://t.me/+6mjOnBFUR9xjN2U1) group if you haven’t done yet.

Author:

Pari Tomar ([_Twitter_](https://twitter.com/tomarpari90) || [_LinkedIn_](https://www.linkedin.com/in/pari-tomar-8b1370187/)), always open to feedback and learning.

BTW, if you would know anyone who would be keen to working with BuildBear. Please have a look over [_here_](https://bit.ly/buildbear-careers)!!!

---

*Originally published on [BuildBear](https://paragraph.com/@buildbear-3/learn-how-to-code-your-own-soulbound-nft-smart-contract)*
