11-21-2024
BSV
$67.44
Vol 204.47m
1.21%
BTC
$98747
Vol 114330.56m
5.39%
BCH
$485.52
Vol 2167.09m
12.51%
LTC
$89.4
Vol 1355.31m
7.5%
DOGE
$0.38
Vol 9382.01m
4.29%
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

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