BSV
$53.44
Vol 29.92m
1.44%
BTC
$95872
Vol 42328.04m
-1.13%
BCH
$449.85
Vol 318.46m
-0.05%
LTC
$100.44
Vol 771.65m
0.88%
DOGE
$0.31
Vol 4409.97m
-0.4%
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

Google unveils ‘Willow’; Bernstein downplays quantum threat to Bitcoin
Google claims that Willow can eliminate common errors associated with quantum computing, while Bernstein analysts noted that Willow’s 105 qubits...
December 18, 2024
WhatsOnChain adds support for 1Sat Ordinals with new API set
WhatsOnChain now supports the 1Sat Ordinals with a set of APIs in beta testing; with this new development, developers can...
December 13, 2024
Advertisement
Advertisement
Advertisement