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);
}
}