Skip to main content

Hello World

This guide provides step-by-step instructions on how to deploy smart contracts on BOB.

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.

Coin Contract

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 the a simple example contract to create a token smart contract.
  • Compile a Smart Contract for BOB: Compile your token smart contract using the development environment.
  • Deploy a Smart Contract to BOB: Deploy your compiled token smart contract to the BOB platform.
  • Interact with a Smart Contract Deployed on BOB: Learn how to interact with the smart contract you've deployed on the BOB platform.

Prerequisites

Before you can deploy smart contracts on BOB, ensure you have the following prerequisites:

  • An EVM wallet with funds from the testnet faucet.
  • Setup either Remix or Foundry as your development environment.

Open the Remix IDE in your browser.

Creating the Coin Contract

Create a new project with Remix. Under contracts folder create a new file Coin.sol.

Enter the below code in Coin.sol file. To learn more about the contract checkout the Solidity tutorial guide.


// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;

contract Coin {
// The keyword "public" makes variables
// accessible from other contracts
address public minter;
mapping(address => uint) public balances;

// Events allow clients to react to specific
// contract changes you declare
event Sent(address from, address to, uint amount);

// Constructor code is only run when the contract
// is created
constructor() {
minter = msg.sender;
}

// Sends an amount of newly created coins to an address
// Can only be called by the contract creator
function mint(address receiver, uint amount) public {
require(msg.sender == minter);
balances[receiver] += amount;
}

// Errors allow you to provide information about
// why an operation failed. They are returned
// to the caller of the function.
error InsufficientBalance(uint requested, uint available);

// Sends an amount of existing coins
// from any caller to an address
function send(address receiver, uint amount) public {
if (amount > balances[msg.sender])
revert InsufficientBalance({
requested: amount,
available: balances[msg.sender]
});

balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Sent(msg.sender, receiver, amount);
}
}

Compile the Coin Contract

To compile contract go to Solidity Compiler section of the IDE, select and compile the Coin smart contract.

You can also directly compile the Coin smart contract by right-clicking on the Coin.sol file and select compile.

Deploy the Coin Contract

To deploy the compiled coin smart contract first open the MetaMask extension and make sure the wallet is connected to the BOB network.

Choose the Remix ENVIRONMENT and Injected Provider - MetaMask. Remix will deploy contract to connected network, i.e., BOB.

Select contract as Coin click Deploy and sign the transaction pop up message on .

Remix IDE image

The contract details will be displayed in the Remix terminal.

Remix IDE terminal image

Interact with the Coin 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 Coin contract from remix IDE under Solidity Compiler section:

Finished

Congratulations!

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

Next Steps

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

Verifying Bitcoin Transactions

You might be interested in verifying Bitcoin transactions on BOB. Checkout the Bitcoin Light Client guide to learn more.

Examples

Checkout a full smart contract and UI example that uses BOB to build a Bitcoin P2P Marketplace.

Join the Discord

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

Notes

Please note the following:

  • Links provided in this guide can change over time. Make sure to check for the most up-to-date resources and documentation.

  • Testnet environments, like the one mentioned in this guide, may be restarted or reset periodically. Be prepared for changes and interruptions in testnet activities.

Feel free to revisit this guide and check for updates or changes in the links and testnet status as needed.

References