Build applications with the Bonsai starter template
How to use this project
Our "Hello, World!" project is intended as a starter template for anyone writing an application using Bonsai. The project repository is here. Everyone is welcome to explore the project source and ask questions on our public Discord, but in order to run this program, you'll need access to the Bonsai proving service. We'll be launching a public version soon, but for now we recommend you sign up for our Bonsai waitlist.
What's in our "Hello, World!" example
This repository implements an application on Ethereum utilizing the Bonsai network as a coprocessor to the smart contract application. It provides a starting point for building powerful new applications on Ethereum that offload computationally intensive or difficult to implement tasks to a RISC Zero guest zkVM, with verified results sent to your Ethereum contract.
Getting Started
Start building your application by forking the Bonsai starter template.
Dependencies
You'll need the following dependencies:
- Rust and Cargo: https://rustup.rs
- Ganache: https://www.npmjs.com/package/ganache#command-line-use
Write Your Application
Get started writing your application by modifying these key files:
- Replace
contracts/contracts/HelloBonsai.sol
with your on-chain application logic. - Replace
methods/guest/src/bin/fibonacci.rs
with your Bonsai coprocessor logic.
Associated build configuration files and tests are discussed along with the project structure below.
Build the Project
Running the following will build the project, including Ethereum contracts and RISC Zero guest program.
cargo build
Run Tests
Running the following will run all tests, including tests for Ethereum contracts and the RISC Zero guest program.
cargo test
Project Structure
.
├── Cargo.toml
├── README.md
├── cli
│ ├── Cargo.toml
│ └── src
│ └── bin
│ ├── deploy.rs
│ └── poke.rs
├── contracts
│ ├── Cargo.toml
│ ├── build.rs
│ ├── contracts
│ │ ├── HelloBonsai.sol
│ │ ├── IBonsaiProxy.sol
│ │ └── test
│ │ └── MockBonsaiProxy.sol
│ ├── src
│ │ └── lib.rs
│ └── tests
│ └── contract_tests.rs
└── methods
├── Cargo.toml
├── build.rs
├── guest
│ ├── Cargo.toml
│ └── src
│ └── bin
│ └── fibonacci.rs
└── src
└── lib.rs
Contracts
Ethereum contracts are in the contracts
directory.
Solidity can be found in contracts/contracts
including the application source and an interface and mock implementation of the Bonsai proxy.
The build configuration is in contracts/build.rs
. Contracts are built and tested with Cargo with the Rust ethers libraries.
Tests are defined in contracts/tests
. They are written in Rust and run against Ganache.
Methods
RISC Zero guest programs are defined in the methods
directory.
CLI
A starter CLI is provided to help deploy contracts to Ethereum and RISC Zero guest programs to Bonsai. Additionally the CLI includes example commands to interact with the smart contract via ethers.