Rust algonaut aims at becoming a rusty SDK for Algorand. Please, be aware that this crate is a work in progress.
use algonaut::algod::AlgodBuilder;
use algonaut::core::MicroAlgos;
use algonaut::transaction::{Pay, TxnBuilder};
use algonaut_transaction::account::Account;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let algod = AlgodBuilder::new()
.bind("http://localhost:4001")
.auth("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
.build_v2()?;
// an account with some funds
let from_account = Account::from_mnemonic("fire enlist diesel stamp nuclear chunk student stumble call snow flock brush example slab guide choice option recall south kangaroo hundred matrix school above zero")?;
let to_address = "2FMLYJHYQWRHMFKRHKTKX5UNB5DGO65U57O3YVLWUJWKRE4YYJYC2CWWBY".parse()?;
// algod has a convenient method that retrieves basic information for a transaction
let params = algod.transaction_params().await?;
// we are ready to build the transaction
let t = TxnBuilder::new()
.sender(from_account.address())
.first_valid(params.last_round)
.last_valid(params.last_round + 10)
.genesis_id(params.genesis_id)
.genesis_hash(params.genesis_hash)
.fee(MicroAlgos(10_000))
.payment(
Pay::new()
.amount(MicroAlgos(123_456))
.to(to_address)
.build(),
)
.build();
// we need to sign the transaction to prove that we own the sender address
let signed_t = from_account.sign_transaction(&t)?;
// broadcast the transaction to the network
let send_response = algod.broadcast_signed_transaction(&signed_t).await?;
println!("Transaction ID: {}", send_response.tx_id);
Ok(())
}
- Example-driven API development
- Async requests
- Builder pattern and sensible defaults
- Modularity
- Clear error messages
- Thorough test suite
- Comprehensive documentation
algonaut
has a modular structure and is composed of multiple crates.
algonaut_client
contains clients foralgod
,kmd
, andindexer
RPC APIs.algonaut_core
defines core structures for Algorand like:Address
,Round
,MicroAlgos
, etc.algonaut_crypto
contains crypto utilities such as:ed25519
andmnemonics
.algonaut_encoding
implements encoding utility functions such asserde
visitors.algonaut_transaction
support developers in building all kinds of Algorand transactions.
Planned:
algonaut_teal
will add validators, templates, and dryrun helpers.
Read the changelog for more details.
Do you want to help with the development? Please find out how by reading our contributions guidelines.
This crate is based on the work of @mraof.
Licensed under MIT license. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be licensed as above, without any additional terms or conditions.
Ferris Algonaut is licensed under a Creative Commons Attribution 4.0 International License.