Proof of stake using the SDK
You can use the SDK to construct proof-of-stake related transactions.
Bond Transactions
This code will construct, sign, and submit a bond transaction to the chain. This code assumes Alice's keys already exist in the wallet and that you know the valid address of a target validator.
use namada_sdk::token::Amount;
use namada_sdk::signing::default_sign;
let alice_addr = sdk.wallet().await.find_address("alice".to_string())
.expect("Invalid alias").into_owned();
let validator_addr = Address::from_str("tnam1qykv7yvcx8eyjld4kuumg0whwjq8usulwy7uhlsw")
.expect("Invalid address");
// build the bond tx
let bond_tx_builder = sdk
.new_bond(validator_addr, Amount::native_whole(100)) // whole amount, ie. 100 NAM
.source(alice_addr)
.signing_keys(vec![alice_acct.public_key.clone()]);
let (mut bond_tx, signing_data) = bond_tx_builder
.build(&sdk)
.await
.expect("Unable to build bond tx");
// sign the tx
sdk.sign(&mut bond_tx, &bond_tx_builder.tx, signing_data, default_sign, ())
.await
.expect("unable to sign bond tx");
//submit to the chain
match sdk.submit(bond_tx, &bond_tx_builder.tx).await {
Ok(res) => println!("Tx result: {:?}", res),
Err(e) => println!("Tx error: {:?}", e)
}
Similar proof of stake transactions such as new_unbond
, new_redelegation
, new_claim_rewards
and new_withdraw
are also available in the SDK.