# Anchoring of L2s

This document provides a comprehensive guide for developers to start their journey with the SatsChain ecosystem, focusing on how to anchor your Layer 2 (L2) solutions on SatsChain. We'll cover everything from setting up your environment to deploying and managing L2 rollups.

The guide includes

1. Run Bitcoin node with inscriptions/Ordinals
2. Deploy Sats Intel and Sats Nuclei
3. Develop L2 Rollup contracts
4. Leverage Compass library for Bitcoin compatibility
5. Deploy rollup contract on Bitcoin
6. Periodic updates on rollup contract

### 1. Run Bitcoin node with inscriptions/Ordinals

Inscriptions allow individual sats to be embedded with content, turning them into Bitcoin-native digital artifacts. These inscriptions are as durable, immutable, secure, and decentralized as Bitcoin. To manage inscriptions, a Bitcoin full node and a specialized ord wallet are required.

#### Installing Bitcoin Core

Bitcoin Core is available from[ bitcoincore.org](https://bitcoincore.org/) on the[ download page](https://bitcoincore.org/en/download/).

Making inscriptions requires Bitcoin Core 24 or newer.

This guide does not cover installing Bitcoin Core in detail. Once Bitcoin Core is installed, you should be able to run bitcoind -version successfully from the command line. Do NOT use bitcoin-qt.

#### Configuring Bitcoin Core

ord requires Bitcoin Core's transaction index and rest interface.

To configure your Bitcoin Core node to maintain a transaction index, add the following to your bitcoin.conf:

txindex=1

Or, run bitcoind with -txindex:

bitcoind -txindex

Details on creating or modifying your bitcoin.conf file can be found[ here](https://github.com/bitcoin/bitcoin/blob/master/doc/bitcoin-conf.md).

#### Syncing the Bitcoin Blockchain

To sync the chain, run:

bitcoind -txindex

…and leave it running until getblockcount:

bitcoin-cli getblockcount

agrees with the block count on a block explorer like[ the mempool.space block explorer](https://mempool.space/). ord interacts with bitcoind, so you should leave bitcoind running in the background when you're using ord.

#### Installing ord

The ord utility is written in Rust and can be built from[ source](https://github.com/ordinals/ord). Pre-built binaries are available on the[ releases page](https://github.com/ordinals/ord/releases).

You can install the latest pre-built binary from the command line with:

curl --proto '=https' --tlsv1.2 -fsLS <https://ordinals.com/install.sh> | bash -s

Once ord is installed, you should be able to run:

ord --version

Which prints out ord's version number.

#### Creating a Wallet

ord uses bitcoind to manage private keys, sign transactions, and broadcast transactions to the Bitcoin network. Additionally the ord wallet requires[ ord server](https://docs.ordinals.com/guides/explorer.html) running in the background. Make sure these programs are running:

bitcoind -txindex

and

ord server

To create a wallet named ord, the default, for use with ord wallet, run:

ord wallet create

This will print out your seed phrase mnemonic, store it somewhere safe.

```
{
  "mnemonic": "dignity buddy actor toast talk crisp city annual tourist orient similar federal",
  "passphrase": ""
}
```

&#x20;&#x20;

If you want to specify a different name or use an ord server running on a non-default URL you can set these options:

ord wallet --name foo --server-url <http://127.0.0.1:8080> create

### Creating Inscriptions

To create an inscription with the contents of FILE, run:

ord wallet inscribe --fee-rate FEE\_RATE --file FILE

\
Ord will output two transactions IDs, one for the commit transaction, and one for the reveal transaction, and the inscription ID. Inscription IDs are of the form TXIDiN, where TXID is the transaction ID of the reveal transaction, and N is the index of the inscription in the reveal transaction.

The commit transaction commits to a tapscript containing the content of the inscription, and the reveal transaction spends from that tapscript, revealing the content on chain and inscribing it on the first sat of the input that contains the corresponding tapscript.

Wait for the reveal transaction to be mined. You can check the status of the commit and reveal transactions using[ the mempool.space block explorer](https://mempool.space/).

Once the reveal transaction has been mined, the inscription ID should be printed when you run:

ord wallet inscriptions

#### Sending Inscriptions

Ask the recipient to generate a new address by running:

ord wallet receive

\
Send the inscription by running:

ord wallet send --fee-rate \<FEE\_RATE> \<ADDRESS> \<INSCRIPTION\_ID>

See the pending transaction with:

ord wallet transactions

\
Once the send transaction is confirmed, the recipient can confirm receipt by running:

ord wallet inscriptions

Content: <https://docs.ordinals.com/guides/wallet.html>

### 2. Deploy Sats Intel and Sats Nuclei

Sats Intel and Sats Nuclei are the two core modules that are required to compute the latest state by interpreting Bitcoin transactions. These modules need not be part of any ring or consensus participation. These can be run independently to compute the state of transactions on its own.&#x20;

#### Sats Intel

Sats Intel is the core intelligence module within the SatsChain ecosystem. It is responsible for converting signed SatsChain transactions into EVM transactions and executing them on Sats Nuclei. The module ensures the seamless integration and operation of smart contracts on the Bitcoin blockchain. It also includes an internal compass module which converts all the native segwit/taproot/inscription architecture to hex address for EVM to understand and run the transactions.&#x20;

#### Sats Nuclei

Stas Nuclei is a customized EVM node for the ecosystem. It provides the Ethereum Virtual Machine (EVM) execution environment and state storage for the Bitcoin blockchain. It ensures that all smart contract transactions from Sats Intel are executed properly. Sats Nuclei leverages a custom Besu node with several modifications and customization to suit SatsChain's needs.

It becomes mandatory to run both the Sats Intel and Sat Nuclei nodes connected together to avail Smart contract functionalities on Bitcoin.

Our team is doing incremental rollout of the codebase of SatsIntel and SatsNuclei which will eventually be open-sourced. Kindly contact the team at [query@SatsChain.xyz](mailto:query@satschain.xyz) in case you need to run these modules for your usecase. Alternatively, you can get API keys from the team by requesting over the mail for quick integration and reduced TAT for running your DApps.&#x20;

### 3. Develop L2 Rollup contracts

Implement an L2 Contract on SatsChain; Your contract type and functionality will differ based on the kind of RollUp you aim to build.

#### **Optimistic Rollups**

1. Batch Transactions: Group multiple transactions into a single batch.
2. Post State Roots: Submit the state root of the batch to SatsChain.
3. Implement Fraud Proofs: Ensure a system for generating and verifying fraud proofs.

#### **Zero-Knowledge (ZK) Rollups**

1. Develop Zero-Knowledge Proof Mechanisms: Create cryptographic proofs for batched transactions.
2. Batch Transactions: Group transactions and generate zero-knowledge proofs.
3. Post Proofs to SatsChain: Submit proofs to validate the transactions.

Arbitrum is one of the Optimistic rollups on Ethereum, you may like to learn more about it [here](https://docs.arbitrum.io/welcome/arbitrum-gentle-introduction). Similarly, an example of a Zero-Knowledge rollup is ZKSync, learn more about it [here](https://docs.lite.zksync.io/userdocs/).

For your L2, there can be a bunch of contracts with each contract catering to a particular usecase. The exact codebase will depend on the nature of the rollup and the architecture you have designed for your L2. You may get in touch with SatsChain team at [query@SatsChain.xyz](mailto:query@satschain.xyz) to help you out in designing the contracts for anchoring.&#x20;

### 4. Leverage Compass library for Bitcoin compatibility

As we know BTC has segwit and taproot addresses, while EVM addresses are 160-bit hexadecimal numbers. Both of which are ideally incompatible with each other, so we required an address conversion module that would allow, EVM (Sats Nuclei) to understand the addresses referenced in the Smart contract and Sats Intel to receive transactions and send results back with corresponding EVM addresses converted back to BTC addresses.

The Compass Module within the SatsChain ecosystem is designed to bridge this gap between Bitcoin's native infrastructure and the Ethereum Virtual Machine (Sats Nuclei), enabling seamless interoperability and smart contract functionality on the Bitcoin blockchain.

The compass library (a part of the Compass module) is essentially a Solidity contract, that allows users to perform address conversions at runtime inside their EVM Smart Contracts. You should leverage this library to convert BTC addresses in your solidity contract to EVM addresses at runtime, before using them.

### 5. Deploy rollup contract on Bitcoin

Begin by ensuring that your cryptocurrency wallet is set to the correct network. Since SatsChain is presently operational only on the testnet, switch your wallet's network setting to testnet. Connect your wallet to the SatsChain [DApp](https://www.satschain.xyz/compiler) and authorize the connection.

Navigate to the SatsChain [DApp](https://www.satschain.xyz/compiler) and find the "Deploy Smart Contract" option. In the deployment interface, paste your flattened Solidity contract.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXeUY8rsweeYfVInzZT-IsXOmbqgixReBEzRSn5-F1w0zvqgZ3BVE19daIM_07Qr2cT5JUCr3AJoMLQfefoPty4NP0YHXdz7DCK3FwTYhxfVT3kJWnmDFQ79kLFvUqYOEHzH1IMo9Jn1Acf2r-YhQpdvHHoz?key=Us8QOd-WAcnFM_Y2trqTrA" alt=""><figcaption></figcaption></figure>

\\

If your smart contract requires constructor parameters, input these values in the designated fields. Initialize gas\_price and gas\_limit for your contract, and ensure that you are paying enough fee rate in BTC on your inscription.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXfi_EEyogOkaxAZqIP_ADATKigdrPti8tKasJddE3ZLinp6gLhUwhBUZfDY2VDSBRH52wtTL9-J5692aJS6TcdKDG_VtE6TLic-zYa8AlsmZF_j15VbiCYLjIbGJb6H2wx5LnX87Cpa7M-e6RChARVXxSnx?key=Us8QOd-WAcnFM_Y2trqTrA" alt=""><figcaption></figcaption></figure>

\\

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXfBX86t6esXtbLchoPcDQCcHRoOAPqbYG18TLazZhrfTBhRaXg8xqme5jNrlWgyT61FvzdqnV2TExAPA-jQAnAUxJjmEOD1QsDffAEj818WtAOgRwQd7IJAaBD_fTAccGXzBYwT2tNmOciCjDCxE_Pzl6El?key=Us8QOd-WAcnFM_Y2trqTrA" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXdiGCXJMtf1Wu3uVDhuJYHo0TLPmcWzlZlvYjALGnpyzZEaiLDjdZms-ip-JlwqeYutKbJK2RONIyn2Lze4KYTulUCli2GeG4kPAar0toWOvv2CkKglyHolJAnmTau5Rv-XOlZiB2aMwdhq2TtAwe8xkI8?key=Us8QOd-WAcnFM_Y2trqTrA" alt=""><figcaption></figcaption></figure>

With all these formalities out of the way, you are good to deploy.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXeQjQ6Fih_Gpt95JL2VriDaGigTeMjUXBYMk-YB87NSil8RLiHbv_cIYlqWUsizYtSqU8oFHWqwjOTmzXcWqKqfV80HnOURqA0PaLeNrjvbNKntPT_P0DiVF7aRoqyOJsJAYDcuATyxdaZ266dSQV2MB2b9?key=Us8QOd-WAcnFM_Y2trqTrA" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXcMTv1ClWfM_cVbjlZ2EfE1f6h4GKqIWNw3Sx-PxAwlw-_BJBaMyYGcDNIxFSDFPJW0AHSg-tcrttSsdXtpCpzvG-7yIx5JKYIs4rVVSG09akfM2wOz2yBEhknjkAMZ9Vd7pfWKPtCe8QFoI0GJvQ7HfKbK?key=Us8QOd-WAcnFM_Y2trqTrA" alt=""><figcaption></figcaption></figure>

### 6. Periodic updates on rollup contract

Once deployed, your L2 contract on SatsChain can be visualized and interacted with using the SatsChain’s [Explorer](https://explorer.satschain.xyz/). This tool allows you to monitor your contract's transactions and activities in real-time.

To periodically write updates on the batch contract, you need to prepare the L1 transaction in the format required by SatsChain execution layer. You can either leverage SatsChain DApp UI to help you facilitate that OR you can get in touch with SatsChain team over mail or twitter to help you out with the steps to construct these transactions. We even support Blob-type transactions for L2s to push their large batches on Bitcoin.

Once a transaction is created with the relevant format, it needs to be sent to BTC network as an inscription with the necessary attributes. After the transaction gets mined on Bitcoin, it will be picked by Sats Intel & Sats Nuclei modules and will update the state of your rollup contract. You can also see the changes, due to your transaction, in effect on SatsChain Explorer.

\
For further help, do reach us out at [query@SatsChain.xyz](mailto:query@satschain.xyz)

\\
