Altius Transaction SDK (Rust)
A Rust SDK for signing and encoding Altius USD multi-token transactions. Supports the USD Multi-Token fee model (0x7a transaction type).
Installation
Add to your Cargo.toml:
[]
= "0.1"
Usage
Quick Start
use ;
let private_key = generate_private_key;
let client = new?;
let tx_hash = client.transfer_usda.await?; // 1 USD
println!;
Transaction Builder
use ;
let tx = new
.chain_id
.nonce
.gas_limit
.to
.value
.fee_token
.max_fee_per_gas_usd
.build;
API Reference
Wallet & Signing
generate_private_key() -> String
Generate a new random private key.
let private_key = generate_private_key;
private_key_to_address(private_key: &str) -> Result<String>
Derive address from private key.
let address = private_key_to_address?;
Wallet
Wallet struct for transaction signing.
use Wallet;
// Generate new wallet
let wallet = generate?;
// Create from private key
let wallet = from_private_key?;
Transaction Builder
TxBuilder
Builder for USD Multi-Token transactions.
use TxBuilder;
use ;
let tx = new
.chain_id
.nonce
.gas_limit
.to
.value
.fee_token
.max_fee_per_gas_usd
.build;
TxBuilder Methods
| Method | Description |
|---|---|
.chain_id(id: u64) |
Set chain ID |
.nonce(nonce: u64) |
Set transaction nonce |
.gas_limit(limit: u64) |
Set gas limit |
.to(address: Option<Address>) |
Set recipient address |
.to_address(address: Address) |
Set recipient address |
.value(value: U256) |
Set transaction value |
.data(data: Bytes) |
Set input data |
.max_priority_fee_per_gas(gas: u128) |
Set max priority fee |
.max_fee_per_gas(gas: u128) |
Set max fee per gas |
.fee_token(address: Address) |
Set fee token address |
.fee_payer(address: Option<Address>) |
Set fee payer (optional) |
.max_fee_per_gas_usd(usd: u128) |
Set max fee in USD attodollars |
.fee_payer_signature(signature: Bytes) |
Set fee payer signature |
.erc20_transfer(token: Address, to: Address, amount: U256) |
Build ERC20 transfer |
.build() -> TxFields |
Build transaction |
.signature_hash() -> B256 |
Compute signature hash |
.sign(signer: &impl Signer) -> Result<SignedTx> |
Sign transaction |
RPC Client
RpcClient
JSON-RPC client for Altius node.
use RpcClient;
let rpc = new;
RpcClient Methods
| Method | Description |
|---|---|
.new(url: &str) -> Self |
Create RPC client |
.get_chain_id() -> Result<u64> |
Get chain ID |
.get_block_number() -> Result<u64> |
Get latest block |
.get_balance(address: Address) -> Result<U256> |
Get native balance |
.get_nonce(address: Address) -> Result<u64> |
Get transaction count |
.get_code(address: Address) -> Result<Bytes> |
Get contract code |
.call(call: CallRequest) -> Result<Bytes> |
Execute contract call |
.send_raw_transaction(tx: Bytes) -> Result<B256> |
Send signed transaction |
.get_transaction_receipt(hash: B256) -> Result<Option<TransactionReceipt>> |
Get receipt |
.wait_for_receipt(hash: B256, timeout_ms: u64) -> Result<TransactionReceipt> |
Wait for receipt |
.get_erc20_balance(token: Address, owner: Address) -> Result<U256> |
Get ERC20 balance |
Nonce Manager
NonceManager
Manages transaction nonces with caching.
use ;
use Arc;
let rpc = new;
let nm = new;
NonceManager Methods
| Method | Description |
|---|---|
.new(rpc: Arc<RpcClient>, address: Address) -> Self |
Create nonce manager |
.get_nonce() -> Result<u64> |
Get current nonce |
.get_and_increment_nonce() -> Result<u64> |
Get and increment nonce |
.reset_nonce() |
Reset nonce cache |
High-Level Client
TxClient
High-level transaction client.
use TxClient;
let client = new?;
TxClientBuilder
use TxClientBuilder;
let client = new
.fee_token
.base_fee
.gas_limit
.build?;
TxClient Methods
| Method | Description |
|---|---|
.new(private_key: &str, rpc_url: &str, fee_token: &str) -> Result<Self> |
Create client |
.address() -> Address |
Get wallet address |
.chain_id() -> Result<u64> |
Get chain ID |
.get_nonce() -> Result<u64> |
Get current nonce |
.build_erc20_transfer(token: Address, recipient: Address, amount: U256) -> Result<TxBuilder> |
Build ERC20 transfer |
.sign(tx: TxBuilder) -> Result<SignedTransaction> |
Sign transaction |
.send(signed: SignedTransaction) -> Result<String> |
Send transaction |
.send_and_wait(signed: SignedTransaction, timeout_ms: u64) -> Result<TransactionReceipt> |
Send and wait |
.send_erc20_transfer(token: Address, recipient: Address, amount: U256) -> Result<String> |
Send ERC20 transfer |
.transfer_usda(recipient: Address, amount_micro: u64) -> Result<String> |
Transfer USDA |
.fee_token_balance(address: Address) -> Result<U256> |
Get fee token balance |
.native_balance(address: Address) -> Result<U256> |
Get native balance |
.reset_nonce() |
Reset nonce cache |
Utilities
compute_fee_token_address(creator: Address, salt: B256) -> (Address, u64)
Compute deterministic fee token address.
use compute_fee_token_address;
let = compute_fee_token_address;
is_reserved_address(creator: Address, salt: B256) -> bool
Check if address is reserved (index < 256).
use is_reserved_address;
let is_reserved = is_reserved_address;
is_fee_token_prefix(addr: Address) -> bool
Check if address has fee token prefix (0xa170...).
use is_fee_token_prefix;
let has_prefix = is_fee_token_prefix;
is_valid_fee_token_address(addr: Address) -> bool
Check if address is valid fee token (has prefix and not zero).
use is_valid_fee_token_address;
let is_valid = is_valid_fee_token_address;
is_index_reserved(index: u64) -> bool
Check if index is reserved (index < 256).
use is_index_reserved;
let is_reserved = is_index_reserved;
pad_hex(hex: &str, bytes: usize) -> String
Pad hex string to specified length.
use pad_hex;
let padded = pad_hex;
num_to_hex(num: u64, bytes: usize) -> String
Convert number to padded hex.
use num_to_hex;
let hex = num_to_hex;
Constants
| Constant | Type | Description |
|---|---|---|
USDA_ADDRESS |
Address |
USDA Fee Token: 0xa1700000000000000000000000000000000000001 |
FEE_TOKEN_FACTORY_ADDRESS |
Address |
Fee Token Factory: 0xa170000000000000000000000000000000000000 |
FEE_MANAGER_ADDRESS |
Address |
Fee Manager: 0xFE00000000000000000000000000000000000001 |
ZERO_ADDRESS |
Address |
Zero address: 0x0000000000000000000000000000000000000000 |
BASE_FEE_ATTO |
u64 |
Base fee: 50,000,000,000 |
DEFAULT_MAX_FEE_PER_GAS |
u64 |
Default max fee: 100,000,000,000 |
DEFAULT_GAS_LIMIT |
u64 |
Default gas limit: 100,000 |
FAUCET_AMOUNT_MICRO |
u64 |
Faucet amount: 100,000,000 |
FAUCET_AMOUNT_WEI |
u128 |
Faucet amount: 100,000,000,000,000,000,000 |
DEFAULT_FAUCET_AMOUNT |
u128 |
Default faucet amount: 100,000,000,000,000,000,000 |
DEFAULT_FAUCET_AMOUNT_MICRO |
u64 |
Default faucet: 100,000,000 |
TRANSFER_AMOUNT_MICRO |
u64 |
Transfer amount: 10,000,000 |
TRANSFER_AMOUNT_WEI |
u128 |
Transfer amount: 10,000,000,000,000,000,000 |
RESERVED_THRESHOLD |
u64 |
Reserved threshold: 256 |
FAUCET_FEE_TOKEN |
Address |
Default faucet fee token |
Security Note
IMPORTANT: Never transmit private keys over the network. Sign transactions locally and only send the signed raw transaction to the RPC node.
// WRONG - never send private key to server
// client.send_private_key_to_server(private_key).await;
// CORRECT - sign locally, send raw transaction
let signed = client.sign.await?;
rpc.send_raw_transaction.await?;
Transaction Type
This SDK supports the USD Multi-Token fee model (0x7a transaction type):
- fee_token: ERC20 token address used for gas payment
- fee_payer: Account paying the fee (optional, defaults to sender)
- max_fee_per_gas_usd_attodollars: Max gas price in USD attodollars/gas
Key Addresses
| Contract | Address |
|---|---|
| USDA (Fee Token) | 0xa1700000000000000000000000000000000000001 |
| Fee Token Factory | 0xa170000000000000000000000000000000000000 |
| Fee Manager | 0xFE00000000000000000000000000000000000001 |
License
MIT OR Apache-2.0