Skip to main content

Hello Bitcoin

This guide provides step-by-step instructions on how to deploy a smart contract on BOB that interacts with Bitcoin.

BOB is EVM-based and we recommend using the Solidity language to write your smart contracts. The base currency on BOB is ETH. Since BOB is a rollup on Ethereum, you can bridge over ETH from Ethereum to pay for transactions.

tip

If you are new to Solidity, we recommend checking out the Solidity getting started guide to get a better understanding of the language.

Developing Solidity contracts is made a lot easier using a development toolchain. Two of the most popular ones are Remix and Foundry. We will use these tools to develop and deploy our smart contract. We will provide instructions for using Remix and Foundry.

  • Remix is a web-based IDE for writing smart contracts. This is a great option if you do not want to install any software on your computer.
  • Foundry is a Rust-based development environment for writing smart contracts. This is a great option if you want to use a local development environment.

Solidity and a toolchain are sufficient to get you started deploying contracts on BOB. However, since BOB's purpose is to make it easy to interact with Bitcoin, we will also add parts of the BOB SDK as part of the starter kit.

  • BOB Starter Kit: The kit serves as a quick start way to develop on BOB using the BOB SDK. Note: you can deploy any EVM contract on BOB without having to use the BOB SDK contracts. They are primarily a helper when you want to interact with Bitcoin from your smart contracts.

HelloBitcoin Contract

Overview of the contract

  • The contract allows swapping between BTC->USDT and Ordinal->USDT using the BTC relay on testnet without requiring the BTC or ordinals to be bridged to BOB.
  • The contract integrates the BTC relay to enable trustless communication between the Bitcoin blockchain and BOB Sepolia (Testnet).

Objectives

  • Set up a development environment: Learn how to set up a development environment for your BOB smart contract development.
  • Create a Smart Contract for BOB: We will use HelloBitcoin smart contract present in the developer kit.
  • Compile a Smart Contract for BOB: Compile your HelloBitcoin smart contract using the development environment.
  • Deploy a Smart Contract to BOB: Deploy your compiled smart contract to BOB Sepolia (Testnet).
  • Interact with a Smart Contract Deployed on BOB: Learn how to interact with the smart contract you've deployed on BOB Sepolia (Testnet).

Prerequisites

We start with installing the prerequisites for the development environment.

  • Get Sepolia ETH and bridge them to BOB. Use the links on the Connect to BOB page.
  • Setup either Remix or Foundry as your development environment. If you want to get started without having to install software, use Remix. If you are planning to develop more complex contracts, use Foundry.

Follow the steps from the foundry book to install the Foundry toolsuite, which contains the forge, cast, anvil and chisel tools.

Creating the HelloBitcoin Contract

Clone the starter toolkit provided.

git clone https://github.com/bob-collective/bob-starter-kit.git
cd bob-starter-kit

The HelloBitcoin contract should already be present inside the src directory.

Checkout the contract by opening it in your favorite editor or IDE.

tip

If you are using VSCode, use the Solidity plugin to get syntax highlighting and other features.

tip

It's not required to create a new contract, but if you want to create a new contract, you can do so by creating a new file in the src directory.

touch src/<Contract_Name>.sol

Compile the Contract

To compile the contract run the following command:

forge build

Deploy the HelloBitcoin Contract

To deploy the contract via the terminal, you'll need your private key. We recommend generating a separate key for development purposes.

tip

If you are using MetaMask, use this guide to export your private key.

To deploy the compiled smart contract on testnet we will use the HelloBitcoin script present under scripts/HelloBitcoin.sol:

export PRIVATE_KEY=0x<your-private-key>
export USDT_ADDRESS=0xF58de5056b7057D74f957e75bFfe865F571c3fB6
export RPC_URL=https://testnet.rpc.gobob.xyz
export VERIFIER_URL=https://testnet-explorer.gobob.xyz/api?

forge script script/HelloBitcoin.sol --rpc-url=$RPC_URL --broadcast \
--verify --verifier blockscout --verifier-url=$VERIFIER_URL \
--priority-gas-price 1

The output in the terminal should look similar to this:

Script ran successfully.
...
✅ [Success]Hash: 0x7a1653e0a0673bd363c28ebd610eb643b29408087f29bf1565df81ded78d2f8b
Contract Address: 0x14F932d0184d4595A3d152ec13F64A36393701B7
Block: 4325242
Paid: 0.00551169309186155 ETH (1837231 gas * 3.00000005 gwei)

✅ [Success]Hash: 0x1d8edfa2be54524804a69507cc967adbdc34716404c43b0d27b9b2375aaf221c
Contract Address: 0x141eE0F02Df17bE850032D578CC4b3BF7d1c7f4F
Block: 4325242
Paid: 0.0082765501379425 ETH (2758850 gas * 3.00000005 gwei)

Interact with the HelloBitcoin Contract

Checkout the testnet explorer to get contract details using the transaction hash from the previous step.

Contract details on Explorer Image

Get the ABI of HelloBitcoin contract:

forge build --silent && jq '.abi' ./out/HelloBitcoin.sol/HelloBitcoin.json > hello_bitcoin_contract_abi.json

Congratulations! You are done!

Congratulations! You have successfully deployed your first smart contract on BOB.

Extra: Publish and verify the HelloBitcoin Contract

The deployment script provided above already handles contract verification.

You can find the contract source code in the "Code" tab, along with new "Read Contract" and "Write Contract" sub-tabs. You are now ready to interact with the contract directly on the explorer.

Verified coin contract on the chain explorer

Next Steps

BOB is built to make it easy to interact with Bitcoin.

Join the Community

Join the Telegram to connect with the community and ask questions.

References