On the left pane, click File explorers > contracts > New File.
In the modal, give any name to your contract. For example, soulbound.sol.
Put in the contract code:
Copy
// SPDX-License-Identifier: MITpragma solidity ^0.8.7;import "@openzeppelin/contracts/token/ERC721/ERC721.sol";import "@openzeppelin/contracts/utils/Counters.sol";import "@openzeppelin/contracts/access/Ownable.sol";contract SoulBoundToken is ERC721, Ownable { using Counters for Counters.Counter; Counters.Counter private _tokenIdCounter; constructor() ERC721("SoulBoundToken", "SBT") {} function safeMint(address to) public onlyOwner { uint256 tokenId = _tokenIdCounter.current(); _tokenIdCounter.increment(); _safeMint(to, tokenId); } function burn(uint256 tokenId) external { require(ownerOf(tokenId) == msg.sender, "Only the owner of the token can burn it."); _burn(tokenId); } function _beforeTokenTransfer(address from, address to, uint256) pure override internal { require(from == address(0) || to == address(0), "This a Soulbound token. It cannot be transferred. It can only be burned by the token owner."); } function _burn(uint256 tokenId) internal override(ERC721) { super._burn(tokenId); }}
This is your soulbound token contract:
It uses the audited OpenZeppelin libraries to make the contract of the ERC-721 standard, belonging to the deployer, and increments each issued token ID by 1.
The contract has a modification to prohibit the token transfer, which makes the issued tokens soulbound.
The contract also implements a burn function to allow the owner of the issued token to be able to burn it.
Compile the contract. On the left pane, click Solidity compiler > Compile.
This will engage your MetaMask to deploy the contract to the Gnosis Chain Chiado testnet through your currently selected MetaMask account. Click Confirm in the MetaMask modal.
Once your contract is deployed, you can view it online at Blockscout Gnosis Chain Chiado testnet explorer.You are now going to verify the contract in the Blockscout explorer to be able to use the explorer as a web app and easily interact with the contract online.
Since your soulbound contract uses imported OpenZeppelin libraries, you must put all the imports into one .sol file to make Blockscout be able to verify it.
In your Remix IDE, click Plugin manager > Flattener > Activate.
Now that your other account has a soulbound token, you can burn it.In your MetaMask instance, switch to the account that has a soulbound token tied to it.
On Blockscout, on your contract, click Write Contract.
In your MetaMask, make sure you have the address selected that owns the issued soulbound token.
Click Connect wallet. This will connect your MetaMask instance with the token owner as the active address.
In burn, provide the token ID. If this is the first issued token, the ID is 0.
Click Write.
This will send the soulbound token from the current owner to the address 0x0000000000000000000000000000000000000000.
This tutorial guided you through the basics of creating and deploying a simple soulbound contract on the Gnosis Chain Chiado testnet through your Chainstack-deployed node.You have also interacted with the contract, issued, and burned the token using Blockscout as a web app and MetaMask as your interaction tool that works through your Chainstack-deployed Gnosis Chain node.
Director of Developer Experience @ Chainstack Talk to me all things Web320 years in technology | 8+ years in Web3 full time years experienceTrusted advisor helping developers navigate the complexities of blockchain infrastructure