Skip to main content
Version: 1.1.0

Flipper example

To quickly start working with Odra, take a look at the following code sample. If you followed the Installation tutorial, you should have this file already at src/

For further explanation of how this code works, see Flipper Internals.

Let's flip
use odra::Var;

/// A module definition. Each module struct consists Vars and Mappings
/// or/and another modules.
pub struct Flipper {
/// The module itself does not store the value,
/// it's a proxy that writes/reads value to/from the host.
value: Var<bool>,

/// Module implementation.
/// To generate entrypoints,
/// an implementation block must be marked as #[odra::module].
impl Flipper {
/// Odra constructor, must be named `init`.
/// Initializes the contract with the value of value.
pub fn init(&mut self) {

/// Replaces the current value with the passed argument.
pub fn set(&mut self, value: bool) {

/// Replaces the current value with the opposite value.
pub fn flip(&mut self) {

/// Retrieves value from the storage.
/// If the value has never been set, the default value is returned.
pub fn get(&self) -> bool {

mod tests {
use crate::flipper::FlipperHostRef;
use odra::host::{Deployer, NoArgs};

fn flipping() {
let env = odra_test::env();
// To test a module we need to deploy it. Autogenerated `FlipperHostRef`
// implements `Deployer` trait, so we can use it to deploy the module.
let mut contract = FlipperHostRef::deploy(&env, NoArgs);

fn test_two_flippers() {
let env = odra_test::env();
let mut contract1 = FlipperHostRef::deploy(&env, NoArgs);
let contract2 = FlipperHostRef::deploy(&env, NoArgs);


To run the tests, execute the following command:

cargo odra test # or add the `-b casper` flag to run tests on the CasperVM

What's next

In the next category of articles, we will go through basic concepts of Odra.