Free Soulbound Token Code for Smart Contracts in Solidity 0.8.9

Soulbound Tokens are a revolutionary technology in Web3. They act as a repository of knowledge, are used to establish identity and can make decentralized governance more secure.

However, they are new and we expect programmers to face a little difficulty in coding it because almost all smart contract token codes till now have an active transfer function.

The following article explains how to create a soulbound token using Solidity 0.8.9.

Soulbound Token Code

// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

contract SoulboundToken {
string public name;
string public symbol;
uint256 public totalSupply;
mapping(address => bool) public soulbound;

event Soulbind(address indexed account);
event UnSoulbind(address indexed account);

constructor(string memory _name, string memory _symbol, uint256 _totalSupply) {
    name = _name;
    symbol = _symbol;
    totalSupply = _totalSupply;
    soulbound[msg.sender] = true;
    emit Soulbind(msg.sender);
}

function soulbind(address _account) external {
    require(!soulbound[_account], "Account is already soulbound");

    soulbound[_account] = true;

    emit Soulbind(_account);
}

function unsoulbind(address _account) external {
    require(soulbound[_account], "Account is not soulbound");

    soulbound[_account] = false;

    emit UnSoulbind(_account);
}

}

Explanation of the Soulbound Token Code

Dhirendra Chandra Das
Dhirendra Chandra Das

Dhirendra is a professional with dual degree MBA specializations in Finance and Marketing. He has a keen interest in finance and crypto. Starting his investment journey in Finance since 2015, Dhirendra has more than 8 years experience in Traditional Finance and 3 years experience in Decentralized Finance.

Articles: 97