1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! 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(¶ms);
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(())
}