This post was first published on Medium. Read Part 1 here and Part 2 here.
Previously, we have shown how to integrate Bitcoin smart contracts with Ordinals, which can be regarded as NFTs on chain. In this article, we show how to integrate them with the fungible version, i.e., BSV-20 tokens. We use auction as an example as before, which works the same as the NFT version with only minimal changes.
How BSV-20 fungible tokens work
BSV-20¹ is a fungible token standard on the BSV network, inspired by the BRC-20 standard on BTC.
Ordinal inscriptions are comprised of a content type, also referred to a MIME type, and content, which is an arbitrary byte string.
In BSV-20, you create an Ordinal inscription output with content type of application/bsv-20 and content of a JSON.
Deploy
For example, to deploy an ordi token with a max supply of 21000000, you create an inscription with the following JSON.
Mint
To mint 1000 ordi tokens, you inscribe the following JSON.
Transfer
Tokens are stored within Unspent Transaction Outputs (UTXOs), much like how native bitcoins are held. To initiate token transfers, you spent the designated UTXO and generate new outputs using the same process as spending regular satoshis, except these new output(s) need to contain transfer inscriptions. This differs from Ordinal NFTs, where the inscription is only needed at minting and is dropped when transferring.
For instance, to transfer the tokens minted above, you would create a transaction with an input spending the minting UTXO (providing the signature and public key normally to spend the P2PKH script), with outputs containing the following inscriptions. It splits the 1000 tokens into three outputs, each containing 100, 500, and 400 tokens, respectively.
For more details on how BSV-20 tokens work, please read the official documentation.
Auctioning BSV-20 tokens
The auction smart contract is the almost same as the one used to auction an ordinal NFT in our previous article.
The only difference lies in the “close” public method. In addition to checking the first output goes to the winning bidder, we also check it contains the expected transfer inscription at the very beginning. If we omit this check, the BSV-20 tokens, carried by the unlocked UTXO, would be deemed burned.
Suppose we are auctioning the 1000 ordi tokens minted above, “this.transferInscription” would be the following:
NOTE:
[1] We use V1, First is first mode, of BSV-20 here. V2, Tickerless Mode, can be supported with slight modification.
Watch: The Bitcoin Masterclasses #1 Day 2 with Craig Wright: Private Identity, Identity Proofs, Topic Reviews
New to blockchain? Check out CoinGeek’s Blockchain for Beginners section, the ultimate resource guide to learn more about blockchain technology.
Author: Eric Knapp
Last Updated: 1698078842
Views: 1239
Rating: 4 / 5 (44 voted)
Reviews: 86% of readers found this page helpful
Name: Eric Knapp
Birthday: 1915-06-03
Address: 386 Tyrone Islands, Frostton, SD 83678
Phone: +3579326472133215
Job: Orthodontist
Hobby: Painting, DIY Electronics, Fencing, Telescope Building, Motorcycling, Orienteering, Video Editing
Introduction: My name is Eric Knapp, I am a venturesome, welcoming, forthright, vibrant, esteemed, audacious, sincere person who loves writing and wants to share my knowledge and understanding with you.