Skip to main content

Setting Up Bonsai

The Bonsai Foundry Template is the best place to start a new Bonsai app using the Bonsai ETH Relay. Its readme will walk you through how to install the necessary dependencies, build the app, and run tests. It includes a prebuilt example (computing Fibonacci numbers), so you can test that everything works properly immediately, without writing any code.

After following the template readme and ensuring tests are passing, you're ready to modify this code and create your own app! Learn how to write code for Bonsai in our articles on writing a zkVM guest program and setting up the ETH Relay for your program.

What does the template provide?

We created the Bonsai Foundry template to give you a clean, self-contained development environment with full proving service mocks and contract tests in Foundry. Because our on-chain mock infrastructure and our ETH relay are locally hosted in Foundry, you'll have access to Foundry tools such as Forge. (If you're unfamiliar, Forge allows you to write tests in plain Solidity).

The template also includes a methods/guest folder. This folder contains the Rust code that will get proven by the [zkVM]. Out of the box, this folder contains a Fibonacci program. To learn more about how to write code for the zkVM, check out our Blockchain Developer's Guide to the zkVM.

How will a fully deployed project use the relay?

Once deployed, your app contract can request off-chain computation results through the ETH relay using familiar Solidity syntax:

    emit CalculateFibonacciCallback(n, result);
fibonnaciCache[n] = result;