algonaut 0.9.0

A Rusty sdk for the Algorand blockchain.
Documentation
//! Call an ARC-4 method on a deployed application via the **dynamic path**:
//! parse a method signature at run time with [`AbiMethod::from_signature`] and
//! build the call with [`Invocation::new`]. Reach for this when the signature
//! is only known at run time (app-spec JSON, user input) or for a quick one-off
//! call.
//!
//! For the recommended, fully-typed path — a client generated at compile time
//! from an ARC-4 ABI or ARC-56 app spec, with arguments type-checked by
//! `cargo build` — use the `contract!` macro instead; see
//! `examples/contract_arc4.rs` and `examples/contract_arc56.rs`.

use algonaut::Algod;
use algonaut::abi::abi_interactions::AbiMethod;
use algonaut::atomic::{AtomicGroupBuilder, Invocation, MethodCall};
use algonaut::core::AppId;
use algonaut::transaction::account::Account;
use dotenv::dotenv;
use std::env;
use std::error::Error;
use std::sync::Arc;
#[macro_use]
extern crate log;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    dotenv().ok();
    env_logger::init();

    info!("creating algod client");
    let algod = Algod::new(&env::var("ALGOD_URL")?, &env::var("ALGOD_TOKEN")?)?;

    info!("creating account for alice");
    let alice = Account::from_mnemonic(&env::var("ALICE_MNEMONIC")?)?;
    let signer = Arc::new(alice.clone());

    info!("retrieving suggested params");
    let params = algod.suggested_params().await?;

    // TODO point this at a real ARC-4 method on a real deployed contract.
    // The signature here is illustrative — `add(uint64,uint64)uint64` takes two
    // unsigned-64 arguments and returns one. This is the dynamic path:
    // `AbiMethod::from_signature` parses the signature at run time. For a typed
    // client generated from an app spec, see `examples/contract_arc4.rs`.
    info!("building method call");
    let call = MethodCall::builder(AppId(5), alice.address(), signer)
        .invoke(Invocation::new(
            AbiMethod::from_signature("add(uint64,uint64)uint64")?,
            [2u64, 3u64],
        ))
        .build(&params);

    info!("composing and executing");
    let result = AtomicGroupBuilder::new()
        .add_method_call(call)
        .build()?
        .sign()
        .await?
        .execute(&algod)
        .await?;
    info!("confirmed in round {:?}", result.confirmed_round);
    for r in result.method_results {
        info!("method return: {:?}", r.return_value);
    }

    Ok(())
}