Skip to main content

Overview

Since developing smart contract-based applications on UTXO-model chains is a vastly different experience compared to other account-model chains like Ethereum, certain fundamental principles should be established whenever you intend to build a CAT protocol-based application.

  • Design your application’s logic from the very beginning based on the UTXO model.
  • The primary function of the layer-1 smart contract is verification, not computation.
  • There are still some limitations on the network, so you need to understand how to make trade-offs.

Installation

You can install the cat-sdk by executing this command:

npm i @cat-protocol/cat-sdk

Architecture

The CAT protocol is designed to work on the Bitcoin network if OP_CAT is enabled. Currently, it functions effectively on the Fractal Bitcoin Network, which is highly similar to the Bitcoin Network but with OP_CAT enabled. To construct decentralized applications based on the CAT protocol, here's our recommended architecture design.

App

Let’s begin with the idea that you’re planning to develop an app with certain features that enable users to interact with CAT20 or CAT721 tokens.

Signer

Since there are many wallets that your app wants to allow users to connect to, you can just use interfaces of Signer to simplify the process of signing transactions. By abstracting the wallet as the signer, the application can be decoupled from the implementation of signing transactions from specific wallets.

Feature

Your app or library can offer some features that can be easily accessed through simple APIs by other parts of your application or even third-party developers without revealing the intricate details of the underlying structure of transactions, covenants, and so on. For instance, if you want to provide a feature, you might need to write some code within your feature function to handle transaction creation, signing, and broadcasting, as well as UTXO management tasks. This could involve multiple transactions and covenants within a single feature.

Covenant

An exciting fact about the OP_CAT is that we can create “covenants” on the Bitcoin Network. A covenant is essentially a way to control the structure of future spending transactions for a specific UTXO. By utilizing the existing Bitcoin technology, such as Segwit and Taproot, you can develop highly advanced covenants that surpass people’s current imagination. It plays a very important role in the CAT protocol-based applications. When designing your own covenants, it’s better to make them modular and composable with others. This could involve multiple smart contracts within a single covenant.

Smart Contract

By simply using sCrypt’s DSL, you can effortlessly write smart contracts. In general terms, an sCrypt smart contract represents how you want to control the spending conditions of a specific UTXO. Unlike the concept of “covenant,” you can treat smart contracts as Bitcoin script that you can read and write without having to grapple with the steep learning curve of the Bitcoin Stack-based virtual machine.

Bitcoin Script

All of the sCrypt smart contracts would be compiled into Bitcoin scripts and included in the corresponding transactions. These scripts would then be verified by miners when they include these transactions in blocks.

SDK Summary

The cat-sdk offers some useful APIs that can be used when building applications. Additionally, it provides a good example that adheres to the architecture design previously discussed.

  • Features: On a high level, this SDK offers some fundamental functionalities to interact with CAT20 and CAT721 protocol tokens, including Deploy, Mint, Transfer, and Burn. These APIs can be found in the src/features folder.

  • Covenants: On a middle level, this SDK introduces an abstraction called the Covenant, which merges the capabilities of the underlying smart contracts and Taproot technology. These covenants are meticulously designed to be modular and composable, enabling the creation of arbitrary transactions to implement customized logic. They can be compared to the building blocks that constitute features.

  • Smart Contracts: On a fundamental level, this SDK offers all the essential smart contracts written in the sCrypt DSL, which can be compiled into Bitcoin scripts and utilized in covenants. If you’re interested in learning how to create your own on-chain smart contracts, you should thoroughly examine these contracts in the src/contracts folder.

You can access the source code of the SDK from here. We hope you had a wonderful journey with the CAT protocol.