Crate aleo_agent

Source
Expand description

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:

Modules§

account
Account implementations
agent
The main Agent module. Contains the Agent types and all associated structures
builder
A builder for an Agent
chain
Node APIs
deploy
program deployment implementation
program
Tools for executing, and managing programs on the Aleo network Program management object for loading programs for building, execution, and deployment

Structs§

BlockMemory
An in-memory block storage.
Record
A value stored in program record.
Testnet3

Enums§

Entry
An entry stored in program data.
Literal
The literal enum represents all supported types in snarkVM.

Constants§

DEFAULT_BASE_URL
DEFAULT_TESTNET
MAINNET
MICROCREDITS

Traits§

Network
Uniform
A trait for a uniform random number generator.

Type Aliases§

Address
Block
BlockHash
Ciphertext
CiphertextRecord
ConfirmedTransaction
ConsensusMemory
ConsensusStore
CurrentNetwork
Field
Group
Identifier
Package
Plaintext
PlaintextRecord
PrivateKey
Program
ProgramID
Query
Signature
Transaction
TransactionID
Transactions
TransitionID
VM
Value
ViewKey