BSV
$47.03
Vol 15.1m
3.91%
BTC
$69614
Vol 45742.54m
2.56%
BCH
$344
Vol 249.59m
4.59%
LTC
$66.02
Vol 377.54m
0.77%
DOGE
$0.17
Vol 4662.11m
8.23%
Getting your Trinity Audio player ready...

This post was first published on Medium.

Combine Ordinals tokens & sCrypt smart contracts

Recently, Ordinals have attracted considerable interest in the BTC realm. One purported major limitation of Ordinals is their lack of smart contract support, in contrast to other token standards like Ethereum’s ERC-721.

We demonstrate the process of incorporating sCrypt smart contracts into Ordinals, tremendously expanding the range of potential use cases. Contrary to common belief, Ordinals are composable with arbitrary smart contracts since day 1.

sCrypt and Ordinals logos
Image Source

Basic Idea

An ordinal is essentially a satoshi with a unique sequence number, ‘inscribed’ with data. This inscription permanently associates the data with the satoshi, effectively transforming it into an NFT. The inscription data is held within an envelope, a chunk of Bitcoin script that never gets executed.

For instance, a text inscription of the string ‘Hello, World!’ might look like the following:

OP_FALSE script

OP_FALSE ensures that the inscription script never enters the OP_IF branch and remains unexecuted. The entire inscription script can be considered as a NOP (No Operation) and can be combined with other scripts without affecting their execution. Commonly, they are concatenated with a simple script for validate signatures.

In the context of sCrypt, it is added at the beginning of the script generated from the sCrypt smart contract compilation. It does not alter the contract’s behavior and can be seamlessly combined with any contract without causing any issues, thus adding smart contract capability to any ordinals.

<Envelope Script> <Smart Contract Script>

Taproot

Inscription envelopes, along with the entire locking script, are included in a tapscript. Because taproot script spends can only occur from pre-existing taproot outputs, inscriptions are executed through a two-stage commit/reveal process. Initially, a commit transaction is broadcasted, creating a taproot output that commits to a script containing the envelope. Subsequently, in the reveal transaction, the output from the commit transaction is spent, thus revealing the inscription content on the blockchain.

Transaction diagram
Transaction diagram showcasing the commit/reveal process

Transfer

Following the minting of the token mentioned earlier, its transfer is controlled by the smart contract, similar to native bitcoins. Each transfer has the capability to relocate the token or satoshi to a different smart contract. It’s important to note that there is no preceding envelope script ensuring transfers, except during the initial inscription.

<Smart Contract Script>

Inscribe an Ordinal with a Smart Contract

The following is an NFT example, containing a simple text inscription with the string “Hello, sCrypt!”:

OrdinalsBot

If we take a look at the NFT’s reveal transaction, we can see that the the input’s witnese contains a large script, that ends with an inscription envelope:

20 0x7526ffac76fab398971f3a1688908961ef0b69bd 20 0x437258615b9ee7d68daaa11d7a9618ac968c59be
20 0xa75e16b064a686048bb9bb98a8e0d48d5baf78fe 20 0x519d8dcc251a72763598de67b77a817653151fcf
20 0x3a97630774dc650878fb11db2760a5b08a3d4412 20 0x02b6a2d36b7f1c6672aef7cd0121f141310a178d
OP_5 OP_PICK OP_5 OP_PICK OP_10 OP_PICK OP_NOP OP_0 OP_PICK OP_HASH160 OP_0 OP_PICK OP_4 OP_PICK
OP_EQUAL OP_NOTIF OP_0 OP_PICK OP_3 OP_PICK OP_EQUAL OP_ELSE OP_1 OP_ENDIF OP_VERIFY OP_0 OP_PICK
OP_3 OP_PICK OP_EQUAL OP_1 OP_ROLL OP_DROP OP_1 OP_ROLL OP_DROP OP_1 OP_ROLL OP_DROP OP_1 OP_ROLL

OP_0 OP_IF 3 0x6f7264 1 0x01 10 0x746578742f706c61696e OP_0 14 0x48656c6c6f2c2073437279707421 OP_ENDIF

The script preceding the envelope is actually the compiled version of an sCrypt smart contract that emulates a gate commitment for BitVM we previously discussed. The ordinal can only be transferred if a valid gate opening is provided, not with a signature.

Potential use cases

The flexibility of ordinals tokens composed with arbitrary smart contracts allows for a wide range of use cases, previously deemed impossible. For example, moving an ordinal into Hash Time-Locked Contract (HTLC), so it can be atomically swapped with another bitcoin or ordinal, also locked in a HLTC.

Watch: Tokens on Bitcoin? 1Sat Ordinals and sCrypt

Recommended for you

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
BSV Association joins OnlyDust’s developer event sponsor list
OnlyDust is a network for open-source developers working with blockchain and decentralized projects; its purpose is to connect contributors, maintainers,...
October 23, 2024
Advertisement
Advertisement
Advertisement