odra

Crates.ioodra
lib.rsodra
version1.4.0
sourcesrc
created_at2022-08-09 14:15:01.296195
updated_at2024-10-18 09:29:24.968458
descriptionSmart contracts for Casper Network.
homepagehttps://odra.dev/docs
repositoryhttps://github.com/odradev/odra
max_upload_size
id641831
size7,071
Kuba PÅ‚askonka (kubaplas)

documentation

README

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

Links

Contact

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

by odra.dev
Commit count: 208

cargo fmt