The credits crate provides an interface for managing and handling operations related to credit transactions on the Aleo network. With this crate, you can effortlessly generate, authorize, and execute credit-related transactions like transferring credits, bonding, unbonding, and more.
- Simple Transactions: Easily transfer credits between two accounts.
- Staking & Validators: Bond or unbond microcredits to validators, control validator states, and manage unbonded credits.
First, add credits to your Cargo.toml dependencies:
[dependencies]
credits = "0.1.3"Then, incorporate it in your Rust code:
use credits::Credits;This repository is under active development and is subject to change.
Notably, this repository does not yet support the following:
- Private transfers
- Private join/splits
- Checking the fee is sufficient for a transaction before executing it
use credits::Credits;
use anyhow::Result;
fn main() -> Result<()> {
let rng = &mut rand::thread_rng();
let transaction = Credits::bond_public(
"APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Staker's Private Key
"aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Validator's Address
10_000_000, // Amount (in microcredits)
10_000, // Priority Fee (in microcredits)
false, // Broadcast
rng,
)?.execute()?;
}use credits::Credits;
use anyhow::Result;
fn main() -> Result<()> {
let rng = &mut rand::thread_rng();
let transaction = Credits::unbond_public(
"APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Staker's Private Key
10_000_000, // Amount (in microcredits)
10_000, // Priority Fee (in microcredits)
false, // Broadcast
rng,
)?.execute()?;
}use credits::Credits;
use anyhow::Result;
fn main() -> Result<()> {
let rng = &mut rand::thread_rng();
let transaction = Credits::unbond_delegator_as_validator(
"APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Validator's Private Key
"aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Delegator's Address
10_000, // Priority Fee (in microcredits)
false, // Broadcast
rng,
)?.execute()?;
}use credits::Credits;
use anyhow::Result;
fn main() -> Result<()> {
let rng = &mut rand::thread_rng();
let transaction = Credits::claim_unbond_public(
"APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Staker's Private Key
10_000, // Priority Fee (in microcredits)
false, // Broadcast
rng,
)?.execute()?;
}use credits::Credits;
use anyhow::Result;
fn main() -> Result<()> {
let rng = &mut rand::thread_rng();
let transaction = Credits::set_validator_state(
"APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Validator's Private Key
true, // is_open
10_000, // Priority Fee (in microcredits)
false, // Broadcast
rng,
)?.execute()?;
}use credits::Credits;
use anyhow::Result;
fn main() -> Result<()> {
let rng = &mut rand::thread_rng();
let transaction = Credits::transfer_public(
"APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Sender's Private Key
"aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Recipient's Address
10_000_000, // Amount (in microcredits)
10_000, // Priority Fee (in microcredits)
false, // Broadcast
rng,
)?.execute()?;
}use credits::Credits;
use anyhow::Result;
fn main() -> Result<()> {
let rng = &mut rand::thread_rng();
let transaction = Credits::transfer_public(
"APrivateKey1zkpBdGzC71T2A3D4bfyuPnz5NyJNLhSx3VQxWRMcha3JYtp", // Sender's Private Key
"aleo1r8ak4sfzpljs65lu0cgu6x4pvvq6atsdx268auu7nf6wvsv5fgqq6v5p0a", // Recipient's Address
10_000_000, // Amount (in microcredits)
10_000, // Priority Fee (in microcredits)
false, // Broadcast
rng,
)?.execute()?;
}This crate provides a comprehensive set of tests for every function in the credits program.
Use the following to run tests:
cargo testPull requests are welcome. For significant changes, please open an issue first to discuss the intended change.