Guides and Tutorials
Welcome to Corsa's guides and tutorials section. Here you'll find step-by-step instructions for common tasks and use cases. These guides will help you leverage the full power of Corsa's Ethereum Layer 2 solution with integrated Bitcoin functionality.
Table of Contents
How to Send a Bitcoin Transaction from an Ethereum Smart Contract
This guide will walk you through the process of sending a Bitcoin transaction using Corsa's custom precompiles from within an Ethereum smart contract.
Prerequisites
A Corsa node up and running
Basic knowledge of Solidity and Ethereum smart contracts
Some test BTC in your Bitcoin wallet (regtest)
Step 1: Create the Solidity Smart Contract
First, let's create a simple Ethereum smart contract that will interact with the Bitcoin network:
Step 2: Deploy the Smart Contract
Deploy this contract to your Corsa network using your preferred method (Foundry, Hardhat, Remix, etc...)
Step 3: Prepare the Bitcoin Transaction
Prepare your raw Bitcoin transaction off-chain. There are many ways to do this. For users users proficient with this cli, you can use btc-dev-utils for this purpose.
Other options from preparing a raw signed transaction include the Electrum and Sparrow self custodial BTC wallets. Ensure your wallet is configured for the chain you want to use.
Step 4: Send the Bitcoin Transaction
Use web3.js, ethers.js, or Foundry's cast to interact with your deployed smart contract and send the Bitcoin transaction:
That's it! You've successfully sent a Bitcoin transaction from an Ethereum smart contract using OnCorsa.
Decoding a Bitcoin Transaction from an Ethereum Smart Contract
This guide will walk you through the process of decoding a Bitcoin raw transaction using Corsa's custom precompiles from within an Ethereum smart contract.
Prerequisites
An OnCorsa node up and running
Basic knowledge of Solidity and Ethereum smart contracts
A Bitcoin raw transaction to decode
Step 1: Create the Solidity Smart Contract
First, let's create a simple Ethereum smart contract that will decode a Bitcoin transaction:
Step 2: Deploy the Smart Contract
Deploy this contract to your Corsa network using your preferred method (Foundry, Hardhat, Remix, etc...)
Step 3: Prepare the Bitcoin Transaction
You'll need a raw Bitcoin transaction to decode. This is typically a hexadecimal string representing the serialized transaction. For example:
Step 4: Decode the Bitcoin Transaction
Use web3.js, ethers.js, or Foundry's cast to interact with your deployed smart contract and send the Bitcoin transaction:
Step 5: Interpret/ Verify the Results
The decodeBitcoinTransaction function will return a structured BitcoinTx object as defined in the BitcoinTxDecoder
Solidity contract. The fields in this struct can be used to verify the tx recipient, tx amount, locktimes, input txid's, etc...
Verify a Contract on Corsascan
This guide will walk you through how to verify a contract you have deployed to the Corsa network.
Prerequisites
An RPC connection to Corsa
Basic knowledge of Solidity and Ethereum smart contracts
Foundry installed
Option 1: Call forge verify
forge verify
Option 2: Verify with the Corsascan UI
Go to https://scan.oncorsa.com/contract-verification and follow the steps there to verify your contract.
Last updated