| Crates.io | credits |
| lib.rs | credits |
| version | 0.1.3 |
| created_at | 2023-10-08 02:29:33.763232+00 |
| updated_at | 2023-10-22 01:01:24.914811+00 |
| description | An SDK for interfacing with the credits program |
| homepage | |
| repository | https://github.com/howardwu/credits |
| max_upload_size | |
| id | 996862 |
| size | 52,626 |
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.
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:
bond_publicuse 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()?;
}
unbond_publicuse 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()?;
}
unbond_delegator_as_validatoruse 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()?;
}
claim_unbond_publicuse 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()?;
}
set_validator_stateuse 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()?;
}
transfer_publicuse 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()?;
}
transfer_public_to_privateuse 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 test
Pull requests are welcome. For significant changes, please open an issue first to discuss the intended change.