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: odra::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§
- This module provides types and traits for working with entrypoint arguments.
- Safe, overflowing addition and subtraction utilities.
- Encapsulates a set of structures that abstract out a smart contract layout.
- A module that contains structs representing entry points and entry point callers.
- A module that provides the interface for interacting with the host environment.
- Module definition and implementation.
- Macros for creating Odra modules that store values in named keys or dictionaries.
- Common API for
no_std
andstd
to access alloc and core crate types. - Unsigned integer utilities.
- General purpose utilities.
Structs§
- Represents a call definition, which includes the method name, runtime arguments, attached value, and mutability flag.
- Represents the result of a contract call.
- Represents the environment accessible in the contract context.
- Represents the environment accessible in the contract execution context.
- A module component that is a reference to an external contract.
- A Vector of deploy reports makes a full gas report.
- Data structure for an indexed, iterable collection.
- An iterator over the elements of a
List
. - Data structure for storing key-value pairs.
- A module that stores a single value in the storage that can be read or incremented.
- A wrapper struct for a module implementing the Module trait.
- Data structure for storing a single value.
Enums§
- An enum representing an
AccountHash
or aContractPackageHash
. - Error that can occur while operating on an Address.
- Error that can occur while operating on a collection.
- Represents a deploy report, which includes the gas used and the deploy details.
- Event-related errors.
- An error that can occur during smart contract execution
- General error type in Odra framework
- An internal virtual machine error
Traits§
- A trait for types that can be converted into an
Address
. - Trait representing the context of a smart contract.
- Trait that needs to be implemented by all contract refs.
- The contract trait.
- A trait that allows safe unwrapping in the context of a smart contract. On failure the contract does not panic, but reverts calling
ContractEnv::revert
. Works withResult
andOption
.
Type Aliases§
- Represents the result of a contract call.
Attribute Macros§
- This macro is used to implement the boilerplate code for the event and contract schema.
- Provides implementation of a reference to an external contract.
- Core element of the Odra framework, entry point for writing smart contracts.
- Implements
Into<odra::OdraError>
for an error enum. - Implements boilerplate for a type to be used in an Odra module.
Derive Macros§
- Implements
Into<odra::casper_types::RuntimeArgs>
for a struct.