23 releases (6 stable)

new 1.5.0 Jan 7, 2025
1.4.0 Oct 18, 2024
1.3.0 Sep 20, 2024
1.2.0 Jul 30, 2024
0.2.0 Nov 23, 2022

#362 in Magic Beans

Download history 205/week @ 2024-09-20 25/week @ 2024-09-27 10/week @ 2024-10-04 9/week @ 2024-10-11 173/week @ 2024-10-18 3/week @ 2024-10-25 11/week @ 2024-11-01 11/week @ 2024-11-08 21/week @ 2024-11-15 28/week @ 2024-11-22 3/week @ 2024-11-29 99/week @ 2024-12-06 16/week @ 2024-12-13 1/week @ 2024-12-20 117/week @ 2025-01-03

185 downloads per month
Used in odra-modules

MIT license

220KB
4.5K SLoC

Odra - Smart contracts for Casper Network.

Docs | Installation | Tutorials | Cargo Odra | Discord | Blog

GitHub Workflow Status Code coverage Version License Language

Table of Contents

Usage

Use Cargo Odra to generate, build and test you code.

Example

use odra::prelude::*;
use odra::Var;

#[odra::module]
pub struct Flipper {
    value: Var<bool>,
}

#[odra::module]
impl Flipper {
    pub fn init(&mut self) {
        self.value.set(false);
    }

    pub fn set(&mut self, value: bool) {
        self.value.set(value);
    }

    pub fn flip(&mut self) {
        self.value.set(!self.get());
    }

    pub fn get(&self) -> bool {
        self.value.get_or_default()
    }
}

#[cfg(test)]
mod tests {
    use crate::flipper::FlipperHostRef;
    use odra::host::{Deployer, NoArgs};

    #[test]
    fn flipping() {
        let env = odra_test::env();
        let mut contract = FlipperHostRef::deploy(&env, NoArgs);
        assert!(!contract.get());
        contract.flip();
        assert!(contract.get());
    }
}

Checkout our examples. It shows most of Odra features.

Tests

Before running tests make sure you have following packages installed:

Run tests:

$ just test

Contact

Need some help? Write to contract@odra.dev.

Dependencies

~10MB
~204K SLoC