11-22-2024
BSV
$67.2
Vol 146.2m
-9.2%
BTC
$98925
Vol 103244.13m
0.94%
BCH
$490.81
Vol 1279.18m
-6.09%
LTC
$91.66
Vol 1135.05m
2.1%
DOGE
$0.39
Vol 10346m
2.51%
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

David Case gets technical with Bitcoin masterclass coding sessions
Whether you're a coding pro or a novice, David Case's livestream sessions on the X platform are not to be...
November 21, 2024
NY Supreme Court’s ruling saves BTC miner Greenidge from closing
However, the judge also ruled that Greenidge must reapply for the permit and that the Department of Environmental Conservation has...
November 20, 2024
Advertisement
Advertisement
Advertisement