19 releases (2 stable)

1.1.0 Jun 17, 2024
0.9.1 Apr 15, 2024
0.8.1 Mar 1, 2024
0.7.1 Dec 13, 2023
0.2.0 Nov 23, 2022

#631 in Magic Beans

Download history 68/week @ 2024-03-25 191/week @ 2024-04-01 152/week @ 2024-04-15 77/week @ 2024-05-06 98/week @ 2024-05-13 170/week @ 2024-05-20 10/week @ 2024-06-10 183/week @ 2024-06-17 6/week @ 2024-06-24 4/week @ 2024-07-01

203 downloads per month
Used in odra-modules

MIT license

225KB
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

~9.5MB
~198K SLoC