2 releases (1 stable)
1.0.1 | May 8, 2024 |
---|---|
1.0.0-alpha | May 7, 2024 |
#1263 in Data structures
65KB
1K
SLoC
aleo-agent
aleo-agent is a simple-to-use library to interact with the Aleo Network in Rust
lib.rs
:
The aleo-agent
is a simple-to-use library that enables you to
build applications and interact with the Aleo Network using Rust.
Overview
The aleo-agent
provides a set of tools for deploying and executing programs, as well as
tools for communicating with the Aleo Network.
The agent is designed to expose both low-level APIs for communicating with the Aleo Network Node API and higher-level APIs for communicating with deployed programs.
Example
In this example, a call to the Aleo network demonstrates how to create an agent to access its own public balance and transfer 1 credit (equivalent to 1,000,000 microcredits) from the public balance to a recipient address.
use aleo_agent::account::Account;
use aleo_agent::agent::{Agent, TransferArgs, TransferType};
use aleo_agent::{Address, MICROCREDITS};
use anyhow::Result;
use std::str::FromStr;
// recipient address format: aleo1...
fn transfer_public_balance(recipient_address : &str) -> Result<()> {
// private key format: APrivateKey1zkp...
let private_key = "YOUR PRIVATE KEY";
// build an account using the private key
let account = Account::from_private_key(private_key)?;
// build an agent using the account
let agent = Agent::builder().with_account(account).build();
let public_balance = agent.get_public_balance()?;
println!("Public Balance : {}", public_balance);
let recipient_address = Address::from_str(recipient_address).expect("Invalid recipient address");
// transfer 1 credit to recipient_address
let transfer_args = TransferArgs::from(
MICROCREDITS, // 1 credit
recipient_address,
1,
None,
TransferType::Public,
);
let tx_hash = agent.transfer(transfer_args)?;
println!("Transfer tx hash: {}", tx_hash);
Ok(())
}
For more information about the Agent interface used in this example, see the examples in the agent
module.
References
For an introduction to the Aleo Network and the Aleo Program, see the following resources:
Dependencies
~65MB
~1M SLoC