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
Run Bitcoin node with inscriptions/Ordinals
Deploy Sats Intel and Sats Nuclei
Develop L2 Rollup contracts
Leverage Compass library for Bitcoin compatibility
Deploy rollup contract on Bitcoin
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 on the download page.
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.
Syncing the Bitcoin Blockchain
To sync the chain, run:
bitcoind -txindex
Leave it running until getblockcount: bitcoin-cli getblockcount agrees with the block count on a block explorer like the mempool.space block explorer. 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. Pre-built binaries are available on the releases page.
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 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.
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.
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.
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.
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 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 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.
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
Batch Transactions: Group multiple transactions into a single batch.
Post State Roots: Submit the state root of the batch to SatsChain.
Implement Fraud Proofs: Ensure a system for generating and verifying fraud proofs.
Zero-Knowledge (ZK) Rollups
Develop Zero-Knowledge Proof Mechanisms: Create cryptographic proofs for batched transactions.
Batch Transactions: Group transactions and generate zero-knowledge proofs.
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. Similarly, an example of a Zero-Knowledge rollup is ZKSync, learn more about it here.
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 to help you out in designing the contracts for anchoring.
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 and authorize the connection.
Navigate to the SatsChain DApp and find the "Deploy Smart Contract" option. In the deployment interface, paste your flattened Solidity contract.
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.
With all these formalities out of the way, you are good to deploy.
6. Periodic updates on rollup contract
Once deployed, your L2 contract on SatsChain can be visualized and interacted with using the SatsChain’s Explorer. 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
Last updated