How to deploy a Soulbound NFT contract on Binance Smart Chain with thirdweb.

Joshua AdesanyaJoshua Adesanya
3 min read

Introduction

SoulBound NFTs are non-fungible tokens that are intended to be non-transferable; once minted, the owner cannot transfer it to anybody; they are ideal for school certificate NFTs, online course NFTs, and other NFTs that have to do with confirming that someone has completed a task.

ThirdWeb is a complete web3 development framework that can help fast track development and deployment of a smart contract.

If you are interested in deploying a Soulbound NFT contract on Binance Smart Chain with third-party support, this article is for you.

Prerequisites

Basic knowledge of Solidity

Make sure Node/NPM is installed.

Project Setup and Installation

To set up a ThirdWeb project, Open up a terminal and execute these commands.

npx thirdweb create nft-bnb

npx thirdweb create is the command, and nft-bnb is the name of the project.

What type of project do you want to create? - Contract
What framework do you want to use? - Hardhat
What type of contract do you want to start from? -  Empty Contract

After choosing the responses above, all packages will be installed and you can change the directory to nft-bnb.

cd nft-bnb

Soulbound Contract

The directory should contain a contracts folder with a contract.sol file, you should replace the contract.sol file with the code below.

The Soulbound contract expects three arguments, baseURI, NFTName, and NFTShortName. It has a Minted event which is emitted when a new NFT is minted, the contract has the following functions.

mint

_beforeTokenTransfer

_burn

tokenURI

setBaseURI

The mint function is responsible for minting a new NFT, it sets the current tokenId, mints the new NFT to the assigned address, increments the tokenId, and emits the Minted event.

The _beforeTokenTransfer function is an internal function called before any transfer happens, this is where NFT is stopped from being transferred, this function only works if the from address is a zero address.

The _burn function is an internal function that is overring the _burn function in the ERC721 & ERC721URIStorage. It is used to send NFT to the zero address.

The tokenURI function is used to retrieve the tokenURI for the associated tokenId of the NFT. This is mostly derived by a concatenation of the baseURI and the tokenId.

The setBaseURI function is used to set a new baseURI, this can happen if the associated metadata changes after the contract has been deployed.

Deployment

Run the command below

yarn deploy

The above command should redirect you to the third web dashboard below.

You need to make sure you have connected your wallet to the appropriate chain, which is Binance Smart Chain Testnet here.

You can enter the required parameters and click deploy now.

You will be required to sign the transaction to successfully deploy the contract, you should see the image below after the contract has been successfully deployed.

Conclusion

We were able to develop and deploy a soulbond NFT with thirdweb.

Link to deployed contract on thirdweb - https://thirdweb.com/binance-testnet/0xD6A2b75b52F195E1D8C1bEdF1C43B58219A878b1

I hope you found this tutorial useful.

Thank you for reading.

References

https://blog.thirdweb.com/guides/how-to-deploy-erc721a-nft-smart-contract/

0
Subscribe to my newsletter

Read articles from Joshua Adesanya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Joshua Adesanya
Joshua Adesanya

I am a passionate software developer who loves to build quality software that users love to use. I work with both frontend and backend technologies. I am currently learning blockchain technologies and building in the web3 space.