Expand description
A Rust library for writing smart contracts for the Casper Blockchain.
§Example
The following example is a simple counter smart contract. The contract stores a single value, which can be incremented or decremented. The counter value can be initialized at contract creation time.
use odra::prelude::*;
#[odra::module]
struct Counter {
count: Var<u32>,
}
#[odra::module]
impl Counter {
pub fn init(&mut self, count: u32) {
self.count.set(count);
}
pub fn increment(&mut self) {
self.count.set(self.count.get_or_default() + 1);
}
pub fn decrement(&mut self) {
self.count.set(self.count.get_or_default() - 1);
}
pub fn get_count(&self) -> u32 {
self.count.get_or_default()
}
}
Re-exports§
pub use odra_core::casper_event_standard;
pub use odra_core::casper_types;
pub use odra_schema as schema;
Modules§
- args
- This module provides types and traits for working with entrypoint arguments.
- contract_
def - Encapsulates a set of structures that abstract out a smart contract layout.
- entry_
point_ callback - A module that contains structs representing entry points and entry point callers.
- host
- A module that provides the interface for interacting with the host environment.
- module
- Module definition and implementation.
- named_
keys - Macros for creating Odra modules that store values in named keys or dictionaries.
- prelude
- Common API for
no_std
andstd
to access alloc and core crate types. - uints
- Unsigned integer utilities.
- utils
- General purpose utilities.
Structs§
- CallDef
- Represents a call definition, which includes the method name, runtime arguments, attached value, and mutability flag.
- Contract
Call Result - Represents the result of a contract call.
- Contract
Env - Represents the environment accessible in the contract context.
- Execution
Env - Represents the environment accessible in the contract execution context.
- GasReport
- A Vector of deploy reports makes a full gas report.
Enums§
- Address
Error - Error that can occur while operating on an Address.
- Collection
Error - Error that can occur while operating on a collection.
- Deploy
Report - Represents a deploy report, which includes the gas used and the deploy details.
- Event
Error - Event-related errors.
- VmError
- An internal virtual machine error
Traits§
- Contract
Context - Trait representing the context of a smart contract.
- Contract
Ref - Trait that needs to be implemented by all contract refs.
- Odra
Contract - The contract trait.
Attribute Macros§
- event
- This macro is used to implement the boilerplate code for the event and contract schema.
- external_
contract - Provides implementation of a reference to an external contract.
- module
- Core element of the Odra framework, entry point for writing smart contracts.
- odra_
error - Implements
Into<OdraError>
for an error enum. - odra_
type - Implements boilerplate for a type to be used in an Odra module.
Derive Macros§
- Event
- Into
Runtime Args - Implements
Into<odra::casper_types::RuntimeArgs>
for a struct.