aleo_agent/
lib.rs

1//! The `aleo-agent` is a simple-to-use library that enables you to
2//! build applications and interact with the [Aleo Network](https://aleo.org) using Rust.
3//!
4//! ## Overview
5//! The `aleo-agent` provides a set of tools for deploying and executing programs, as well as
6//! tools for communicating with the Aleo Network.
7//!
8//! The agent is designed to expose both low-level APIs for communicating with the
9//! Aleo Network [Node API](https://github.com/AleoHQ/snarkOS/blob/fc340c679960e63612c536d69e71405b77e113f4/node/rest/src/lib.rs#L131) 
10//! and higher-level APIs for communicating with deployed programs.
11//!
12//! ## Example
13//!
14//! In this example, a call to the Aleo network demonstrates how to create an agent to access its own public balance and
15//! transfer 1 credit (equivalent to 1,000,000 microcredits) from the public balance to a recipient address.
16//!
17//! ```
18//! use aleo_agent::account::Account;
19//! use aleo_agent::agent::{Agent, TransferArgs, TransferType};
20//! use aleo_agent::{Address, MICROCREDITS};
21//! use anyhow::Result;
22//! use std::str::FromStr;
23//!
24//! // recipient address format: aleo1...
25//! fn transfer_public_balance(recipient_address : &str) -> Result<()> {
26//!     // private key format: APrivateKey1zkp...
27//!     let private_key = "YOUR PRIVATE KEY";
28//!     // build an account using the private key
29//!     let account = Account::from_private_key(private_key)?;
30//!     // build an agent using the account
31//!     let agent = Agent::builder().with_account(account).build();
32//!     
33//!     let public_balance = agent.get_public_balance()?;
34//!     println!("Public Balance : {}", public_balance);
35//!     
36//!     let recipient_address = Address::from_str(recipient_address).expect("Invalid recipient address");
37//!     // transfer 1 credit to recipient_address
38//!     let transfer_args = TransferArgs::from(
39//!         MICROCREDITS, // 1 credit
40//!         recipient_address,
41//!         1,
42//!         None,
43//!         TransferType::Public,
44//!     );
45//!     let tx_hash = agent.transfer(transfer_args)?;
46//!     println!("Transfer tx hash: {}", tx_hash);
47//!     
48//!     Ok(())
49//! }
50//! ```
51//! For more information about the Agent interface used in this example, see the examples in the `agent` module.
52//!
53//! ## References
54//! For an introduction to the Aleo Network and the Aleo Program,
55//! see the following resources:
56//!
57//! - [SnarkOS](https://github.com/AleoHQ/snarkOS)
58//! - [SnarkVM](https://github.com/AleoHQ/snarkVM)
59//! - [Aleo Developer Guide](https://developer.aleo.org/getting_started/)
60
61pub use snarkvm::console::{
62    network::Testnet3,
63    prelude::Uniform,
64    program::{Entry, Literal, Network, Record},
65};
66pub use snarkvm::ledger::store::helpers::memory::BlockMemory;
67
68pub mod account;
69pub mod agent;
70pub mod builder;
71pub mod chain;
72pub mod deploy;
73pub mod program;
74
75// GLOBAL DECLARATIONS
76pub type CurrentNetwork = Testnet3;
77pub type TransactionID = <CurrentNetwork as Network>::TransactionID;
78pub type CiphertextRecord = Record<CurrentNetwork, Ciphertext>;
79pub type PlaintextRecord = Record<CurrentNetwork, Plaintext>;
80pub type BlockHash = <CurrentNetwork as Network>::BlockHash;
81pub type TransitionID = <CurrentNetwork as Network>::TransitionID;
82pub type ProgramID = snarkvm::console::program::ProgramID<CurrentNetwork>;
83pub type Identifier = snarkvm::console::program::Identifier<CurrentNetwork>;
84pub type Value = snarkvm::console::program::Value<CurrentNetwork>;
85pub type Field = snarkvm::console::types::Field<CurrentNetwork>;
86pub type Ciphertext = snarkvm::console::program::Ciphertext<CurrentNetwork>;
87pub type Plaintext = snarkvm::console::program::Plaintext<CurrentNetwork>;
88pub type PrivateKey = snarkvm::console::account::PrivateKey<CurrentNetwork>;
89pub type ViewKey = snarkvm::console::account::ViewKey<CurrentNetwork>;
90pub type Signature = snarkvm::console::account::Signature<CurrentNetwork>;
91pub type Address = snarkvm::console::account::Address<CurrentNetwork>;
92pub type Group = snarkvm::console::account::Group<CurrentNetwork>;
93pub type Query = snarkvm::ledger::query::Query<CurrentNetwork, BlockMemory<CurrentNetwork>>;
94pub type Block = snarkvm::ledger::Block<CurrentNetwork>;
95pub type Transaction = snarkvm::ledger::Transaction<CurrentNetwork>;
96pub type ConfirmedTransaction = snarkvm::ledger::ConfirmedTransaction<CurrentNetwork>;
97pub type Transactions = snarkvm::ledger::Transactions<CurrentNetwork>;
98pub type ConsensusMemory = snarkvm::ledger::store::helpers::memory::ConsensusMemory<CurrentNetwork>;
99pub type ConsensusStore = snarkvm::ledger::store::ConsensusStore<CurrentNetwork, ConsensusMemory>;
100pub type VM = snarkvm::synthesizer::VM<CurrentNetwork, ConsensusMemory>;
101pub type Program = snarkvm::synthesizer::Program<CurrentNetwork>;
102pub type Package = snarkvm::package::Package<CurrentNetwork>;
103
104pub const DEFAULT_BASE_URL: &str = "https://api.explorer.aleo.org/v1";
105pub const DEFAULT_TESTNET: &str = "testnet3";
106pub const MAINNET: &str = "mainnet";
107pub const MICROCREDITS: u64 = 1_000_000; // 1 credit = 1_000_000 microcredits