credits

Crates.iocredits
lib.rscredits
version0.1.3
sourcesrc
created_at2023-10-08 02:29:33.763232
updated_at2023-10-22 01:01:24.914811
descriptionAn SDK for interfacing with the credits program
homepage
repositoryhttps://github.com/howardwu/credits
max_upload_size
id996862
size52,626
Howard Wu (howardwu)

documentation

README

Credits SDK

Crates.io License

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.

Features

  • Simple Transactions: Easily transfer credits between two accounts.
  • Staking & Validators: Bond or unbond microcredits to validators, control validator states, and manage unbonded credits.

Usage

First, add credits to your Cargo.toml dependencies:

[dependencies]
credits = "0.1.3"

Then, incorporate it in your Rust code:

use credits::Credits;

Notice

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

Examples

bond_public

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()?;
}

unbond_public

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()?;
}

unbond_delegator_as_validator

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()?;
}

claim_unbond_public

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()?;
}

set_validator_state

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()?;
}

transfer_public

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()?;
}

transfer_public_to_private

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()?;
}

Testing

This crate provides a comprehensive set of tests for every function in the credits program.

Use the following to run tests:

cargo test

Contributing

Pull requests are welcome. For significant changes, please open an issue first to discuss the intended change.

Commit count: 27

cargo fmt