Github: https://gist.github.com/crazyrabbitLTC/d1298c1666c1fb3f05cf2ff11ecd5a07
We already have all the code necessary to launch a DAO Compatible NFT token! (The OpenZeppelin Contracts Wizard is pretty awesome). Now, we just need to make a few changes to make it “soulbound” (i.e. non-transferable).
In the OpenZeppelin ERC721 Contracts API docs, you will find some hooks that we will use to control the transferability of our tokens.
We are already using function _afterTokenTransfer(address from, address to, uint256 tokenId) but we need to add a new function to check before a token is transferred to stop it from happening.
To block token transfers, add the following to your code:
Now, before anyone sends a token, the require statement will check if: true == false
and when it obviously doesn’t it, will block the transfer with the error message Err. token is SOUL BOUND.
Github: https://gist.github.com/crazyrabbitLTC/4c0fa2bfab0334a36e8575ac0ea5b2ea
Perfect! Now we have a soulbound NFT that can be minted, but not transferred. This is perfect for non-transferable voting systems, or badges that you don’t want participants to sell on the open market. Because we’re using ERC721 with the Votes extension, our new SBT is also ready for use in a DAO with OpenZeppelin Governor.
The final Code:
Enjoy!

