BSV
$52.38
Vol 41.76m
3.34%
BTC
$76671
Vol 73435.59m
2.3%
BCH
$385.41
Vol 377.36m
3.75%
LTC
$72
Vol 466.35m
3.46%
DOGE
$0.19
Vol 5508.28m
1.38%
Getting your Trinity Audio player ready...

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.

BSV-20 Tokens image

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.

Transfer image
Transfer

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.

Last Bid, Close image
Close

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.

Contract code

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

Recommended for you

BSV joins Linux Foundation to advance open standards
The BSV Association has partnered with the Linux Foundation to advance its objective of promoting development that adheres to BSV...
November 6, 2024
How to construct transactions on BSV blockchain with Python
Python coders, it's time to start learning how to build Bitcoin transactions as nChain's Senior Software Engineer, Arthur Gordon, recently...
November 5, 2024
Advertisement
Advertisement
Advertisement