Introduce sCrypt: a Layer-1 Smart Contract Framework for BTC (2024)

Develop Smart Contracts on BTC in TypeScript

We are extremely thrilled to introduce sCrypt: a modern Typescript framework to develop Layer-1 smart contracts on BTC today, no fork needed. One can now write, test, debug, deploy, and call smart contracts in a easy-to-use unified framework using modern developer tools. Any web2 developer can develop smart contract-powered apps on BTC, as long as she knows JavaScript/TypeScript. It serves as a solid foundation to transforming BTC into a smart contract platform.

Introduce sCrypt: a Layer-1 Smart Contract Framework for BTC (2)

Conventionally, BTC is regarded only capable of payments and storing value. Ordinals has changed the misconception by demonstrating it also supports tokens. Another misconception is BTC’s lack of smart contract capabilities. In fact, BTC support smart contracts since day 1, in the form of Bitcoin Script. Hashlocks, timelocks, and multisig are some prominent examples.

One of the biggest hurdle in BTC smart contracts lies in Script. Being a low-level assembly language, Script is extremely difficult to code in and reason about. There is virtually no tool to test, debug, and deploy as in typical software development workflow. Writing smart contract in native Script is cumbersome and error-prone. It quickly becomes intractable when the contract size and complexity grow.

Enter sCrypt. With sCrypt, developers can directly code BTC smart contracts in Typescript, one of the most popular programming language in the world and used by millions of developers every day. sCrypt contracts are compiled into Bitcoin Script.

sCrypt offers a plethora of benefits:

  • No need to learn new programming language. We chose TypeScript because it provides an easy, familiar language (JavaScript), but with type safety, making it easy to get started writing safe smart contracts. There is no need to learn a new programming language or tools if you are already familiar with TypeScript/JavaScript.
  • No need to learn new tools. Web2 developers can reuse millions of existing TypeScript/JavaScript libraries and their favorite tools: Visual Studio Code/WebStorm for IDE, NPM for package management, Jest/Mocha/ Jasmine for testing.

A Working Example

Let us examine a practical smart contract.

The code below represents a simple logical NAND (NOT-AND) gate commitment for BitVM, taken from Figure 2 in its whitepaper. It checks if the two input bits (A, B) and one output bit (E), all committed in advance using hashes, of the gate match, i.e., E = NAND(A, B).

The exact details of how this code works is not important. The central message here is that it is far from what a modern programming language looks like and appears esoteric.

The functionally equivalent is expressed in sCrypt simply as:

Comparing the Script and sCrypt implementations, it is obvious the latter is drastically more friendly and approachable to modern developers. The former is only known by a handful of developers who can code in outdated assembly language, while the latter can be mastered by millions of developers who know JavaScript/TypeScript, or any other Object Oriented programming languages such as Java, C++, or Golang. The more complicated a smart contract gets, the more advantageous it is to develop it in sCrypt than in Script.

The full code is listed below, based on the sCrypt library scrypt-ts-btc.

Deploy and Call Smart Contracts

We use Pay-to-Witness-Script-Hash (P2WSH) for contract deployment. Deployment consists of compiling the smart contracts code to produce script, hashing this script, and placing the hash into a P2WSH transaction (Tx0), which is broadcast to the network.

When someone wants to call the deployed contract, she will embed the full contract script along with the called method’s inputs as witness data in the subsequent transaction (Tx1) spending Tx0.

Introduce sCrypt: a Layer-1 Smart Contract Framework for BTC (3)

Here is the code snippet to deploy and call the contract:

It is worth noting that deploying (Line 8) and calling (Line 12) the contract only takes one single line.

  • Deployment Transaction ID:

a651b22a8fc6d424233d94087d89744694f7710f175d9cd6fe2a0f66b3b35227

  • Call Transaction ID:

fa06d0f10f2642f9f677c105970559b15e8d9281e744b5ddc1da49fafc15b9d7

These transaction IDs represent an instance of the BitVM contract deployed and called on BTC.

The full code of the example is available on GitHub. Interested developers can access the complete code and run it themselves. For more information on sCrypt, please refer to our extensive documentation.

Known Limitations

sCrypt can work on any blockchain that supports Bitcoin Script. This includes Bitcoin forks and Bitcoin-derived chains such as Litecoin and Doge.

BTC has disabled many Script opcodes such as OP_CAT and OP_MUL, greatly limiting the types of smart contracts that can be expressed in sCrypt. The BTC community is actively discussing re-enabling such opcodes and introducing new ones, which will make sCrypt on BTC more powerful than it is today if the proposed changes are accepted.

In the meantime, there are chains that have the full suite of Script opcodes, like Bitcoin SV and MVC. sCrypt reaches its full capacity on these chains today.

Use in Taproot

We use P2WSH type script to embed sCrypt contracts for ease of exposition in the example, which allows maximum script size of 10KB. sCrypt contracts can also be used in Taproot script. They can be made more expressive and complex, since Taproot has a much bigger script size limit of ~4MB.

Compare to other Layer-1s (L1)

There are other attempts to improve Script’s programmability, which we list some below.

  • Miniscript: a standalone language for representing Bitcoin Script in a composable and readable way. It is very limited in scope and less expressive than Script: it can only express signature requirements, timelocks, hash preimages, and arbitrary combinations of these.
  • Simplicity: a work-in-progress low-level programming language with greater flexibility and expressiveness than Bitcoin Script. It requires a fork to implement on BTC.

In contrast to both, sCrypt does not invent a new programming language and just reuses TypeScript, which has a significantly shallower learning curve. Also it provides a more comprehensive framework besides smart contract language, including IDE, package management, debugger, SDK and APIs. That is, it offers everything developers need to build a full-stack app powered by smart contracts.

Compare to Layer-2s (L2)

sCrypt is a Typescript-based domain specific language (DSL) compiled into Bitcoin Script, which runs on BTC today without any fork. It inherits the full security of BTC, thus making it more secure and trustless than any BTC L2.

Having said that, BTC L2 could use more sCrypt features if they also use Script and have more opcodes enabled than BTC L1. In fact, there are already L2s that leverage sCrypt this way, like Note Protocol.

Introduce sCrypt: a Layer-1 Smart Contract Framework for BTC (2024)
Top Articles
Effect of probiotics on giardiasis. Where are we?
What's the best mask in the game? | Fandom
Identifont Upload
South Park Season 26 Kisscartoon
Ventura Craigs List
Category: Star Wars: Galaxy of Heroes | EA Forums
Strange World Showtimes Near Amc Braintree 10
Prices Way Too High Crossword Clue
The Blind Showtimes Near Showcase Cinemas Springdale
What is a basic financial statement?
Ap Chem Unit 8 Progress Check Mcq
Https://Gw.mybeacon.its.state.nc.us/App
The Rise of Breckie Hill: How She Became a Social Media Star | Entertainment
Turning the System On or Off
Valentina Gonzalez Leak
Caliber Collision Burnsville
Find Such That The Following Matrix Is Singular.
Northeastern Nupath
2020 Military Pay Charts – Officer & Enlisted Pay Scales (3.1% Raise)
Aaa Saugus Ma Appointment
Nevermore: What Doesn't Kill
Blue Rain Lubbock
Walmart Near South Lake Tahoe Ca
Busted News Bowie County
Talk To Me Showtimes Near Marcus Valley Grand Cinema
پنل کاربری سایت همسریابی هلو
Skycurve Replacement Mat
Pawn Shop Moline Il
Meet the Characters of Disney’s ‘Moana’
1636 Pokemon Fire Red U Squirrels Download
Albertville Memorial Funeral Home Obituaries
Japanese Emoticons Stars
Salemhex ticket show3
Egg Crutch Glove Envelope
After Transmigrating, The Fat Wife Made A Comeback! Chapter 2209 – Chapter 2209: Love at First Sight - Novel Cool
Boondock Eddie's Menu
Craigslist Neworleans
Arcane Odyssey Stat Reset Potion
Bridger Park Community Garden
A Man Called Otto Showtimes Near Amc Muncie 12
Studio 22 Nashville Review
Ktbs Payroll Login
Japanese Big Natural Boobs
20 bank M&A deals with the largest target asset volume in 2023
Lonely Wife Dating Club בקורות וחוות דעת משתמשים 2021
Thor Majestic 23A Floor Plan
Tricare Dermatologists Near Me
John Wick: Kapitel 4 (2023)
Bradshaw And Range Obituaries
Craigslist Free Cats Near Me
The Goshen News Obituary
San Pedro Sula To Miami Google Flights
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 6220

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.