Bank module¶
The bank module provides functionality for token transfers, balance queries, and banking operations on the Akash Network.
Transaction parameters
All transaction functions support optional parameters like fee_amount
, gas_limit
, and gas_adjustment
. See Transaction parameters for details.
BankClient class¶
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
bank = client.bank
Transactions¶
send()¶
Send tokens with flexible parameters.
def send(wallet, to_address: str, amount: str, denom: str = "uakt", memo: str = "",
fee_amount: str = None, gas_limit: int = None, gas_adjustment: float = 1.2) -> BroadcastResult
Required parameters:
wallet
(AkashWallet
): Wallet to send fromto_address
(str
): Recipient addressamount
(str
): Amount to send in base units (e.g., "1000000" for 1 AKT)
Optional parameters:
denom
(str
): Token denomination (default: "uakt")memo
(str
): Transaction memo (default: "")fee_amount
(str
): Fee amount in uakt (default: None)gas_limit
(int
): Gas limit override (default: None)gas_adjustment
(float
): Multiplier for gas estimation (default: 1.2)
Returns: BroadcastResult
- Transaction result with the following fields:
tx_hash
(str
): Transaction hashcode
(int
): Response code (0 for success)raw_log
(str
): Raw transaction log/error messagesuccess
(bool
): Whether transaction succeededevents
(List[Dict]
): Transaction eventstype
(str
): Event typeattributes
(List[Dict]
): Event attributeskey
(str
): Attribute keyvalue
(str
): Attribute value
Example:
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your twelve word mnemonic phrase here")
recipient_wallet = AkashWallet.generate()
print(f"Sending to: {recipient_wallet.address}")
result = client.bank.send(
wallet=wallet,
to_address=recipient_wallet.address,
amount="5000000",
memo=""
)
if result.success:
print(f"Transfer successful!")
print(f"TX hash: {result.tx_hash}")
print(f"Gas used: {result.gas_used}")
else:
print(f"Transfer failed: {result.log}")
Example with custom parameters:
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic here")
result = client.bank.send(
wallet=wallet,
to_address=recipient_address,
amount="1000000",
fee_amount="15000"
)
result = client.bank.send(
wallet=wallet,
to_address=recipient_address,
amount="1000000",
gas_limit=120000
)
Example using private key:
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_private_key("your_private_key_hex")
print(f"Wallet address: {wallet.address}")
result = client.bank.send(
wallet=wallet,
to_address="akash1recipient_address",
amount="1000000",
memo=""
)
if result.success:
print(f"Transfer successful: {result.tx_hash}")
else:
print(f"Transfer failed: {result.raw_log}")
Queries¶
get_balance()¶
Query the balance of a specific denomination for an address.
Required parameters:
address
(str
): Account address to query
Optional parameters:
denom
(str
): Token denomination (default: "uakt")
Returns: str
- Balance amount as string in base units
Mainnet Examples:
from akash import AkashClient
from akash import AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic here")
my_balance = client.bank.get_balance(wallet.address, "uakt")
my_akt = int(my_balance) / 1_000_000
print(f"Your address: {wallet.address}")
print(f"Your balance: {my_akt:.6f} AKT ({my_balance} uakt)")
mainnet_addresses = {
"Akash Foundation": "akash17xpfvakm2amg962yls6f84z3kell8c5lserqta",
"Community Pool": "akash1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4",
"Validator 1": "akash14kn0kk33szpwus9nh8n87fjel8djx0y070ymmj"
}
print("\nKnown mainnet balances:")
for name, address in mainnet_addresses.items():
try:
balance = client.bank.get_balance(address, "uakt")
akt_amount = int(balance) / 1_000_000
print(f"{name:15}: {akt_amount:>12,.2f} AKT")
except Exception as e:
print(f"{name:15}: Error querying balance")
multi_asset_denoms = [
"uakt",
"ibc/1234567890ABCDEF",
"factory/akash.../token"
]
print(f"\nMulti-asset balance check for {wallet.address}...")
for denom in multi_asset_denoms:
try:
balance = client.bank.get_balance(wallet.address, denom)
if int(balance) > 0:
print(f"{denom}: {balance}")
else:
print(f"{denom}: 0 (no balance)")
except Exception as e:
print(f"{denom}: Query failed ({str(e)[:50]}...)")
Real-time Balance Monitoring:
from akash import AkashClient
import time
client = AkashClient("https://akash-rpc.polkachu.com:443")
def monitor_address_balance(client, address, denom="uakt", interval=30):
"""Monitor an address balance in real-time."""
print(f"Monitoring {address} every {interval}s")
previous_balance = None
while True:
try:
current_balance = client.bank.get_balance(address, denom)
current_akt = int(current_balance) / 1_000_000
if previous_balance is not None:
change = int(current_balance) - int(previous_balance)
if change != 0:
change_akt = change / 1_000_000
symbol = "+" if change > 0 else ""
print(f"Balance changed: {symbol}{change_akt:.6f} AKT")
print(f"Balance: {current_akt:,.6f} AKT")
previous_balance = current_balance
time.sleep(interval)
except KeyboardInterrupt:
print("Monitoring stopped")
break
except Exception as e:
print(f"Error: {e}")
time.sleep(interval)
monitor_address_balance(client, wallet.address)
get_all_balances()¶
Query all token balances for an address.
Required parameters:
address
(str
): Account address to query
Returns: Dict[str, str]
- Dictionary mapping denomination to balance amount
Example:
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic here")
balances = client.bank.get_all_balances(wallet.address)
print(f"All balances for {wallet.address}:")
total_value_akt = 0
for denom, amount in balances.items():
amount_int = int(amount)
if denom == "uakt":
akt_amount = amount_int / 1_000_000
print(f"AKT: {akt_amount:.6f} ({amount} uakt)")
total_value_akt += akt_amount
else:
print(f"{denom}: {amount}")
print(f"Total AKT value: {total_value_akt:.6f}")
get_supply()¶
Query the total supply of a specific token.
Optional parameters:
denom
(str
): Token denomination (default: "uakt")
Returns: Dict[str, Any]
- Supply information with the following fields:
denom
(str
): Token denominationamount
(str
): Total supply amount in base unitsamount_akt
(str
): Formatted amount in AKT (for uakt denomination)
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
supply_info = client.bank.get_supply("uakt")
print(f"Total AKT supply: {supply_info['amount_akt']} AKT")
print(f"Total AKT supply: {supply_info['amount']} uakt")
get_account_info()¶
Get account information including sequence and account number.
Required parameters:
address
(str
): Account address
Returns: Dict[str, Any]
- Account information with fields like sequence, account_number, address
Example:
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic here")
account_info = client.bank.get_account_info(wallet.address)
print(f"Account: {account_info['address']}")
print(f"Account number: {account_info['account_number']}")
print(f"Sequence: {account_info['sequence']}")
Utils¶
estimate_fee()¶
Estimate transaction fees based on message count and gas requirements.
Optional parameters:
message_count
(int
): Number of messages in transaction (default: 1)gas_per_message
(int
): Gas per message (default: 200000)
Returns: Dict[str, Any]
- Fee estimation with the following fields:
gas_limit
(int
): Total gas limitestimated_fee
(int
): Estimated fee in uaktfee_denom
(str
): Fee denominationfee_akt
(float
): Fee amount in AKTmessage_count
(int
): Number of messagesgas_per_message
(int
): Gas per message
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
fee_info = client.bank.estimate_fee()
print(f"Estimated fee: {fee_info['estimated_fee']} uakt")
print(f"Estimated fee: {fee_info['fee_akt']} AKT")
print(f"Gas limit: {fee_info['gas_limit']}")
multi_fee = client.bank.estimate_fee(message_count=3)
print(f"Multi-message fee: {multi_fee['estimated_fee']} uakt")
validate_address()¶
Validate if an address is correctly formatted.
Required parameters:
address
(str
): Address to validate
Returns: bool
- True if valid, False otherwise
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
valid_addr = "akash1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4"
invalid_addr = "cosmos1invalid"
print(f"Valid address: {client.bank.validate_address(valid_addr)}")
print(f"Invalid address: {client.bank.validate_address(invalid_addr)}")
calculate_akt_amount()¶
Convert uAKT (micro-AKT) to AKT.
Required parameters:
uakt_amount
(str
): Amount in uAKT as string
Returns: float
- Amount in AKT
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
uakt_balance = "1500000"
akt_amount = client.bank.calculate_akt_amount(uakt_balance)
print(f"{uakt_balance} uakt = {akt_amount} AKT")
calculate_uakt_amount()¶
Convert AKT to uAKT (micro-AKT).
Required parameters:
akt_amount
(float
): Amount in AKT as float
Returns: str
- Amount in uAKT as string
Example:
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic here")
akt_to_send = 1.5
uakt_amount = client.bank.calculate_uakt_amount(akt_to_send)
print(f"{akt_to_send} AKT = {uakt_amount} uakt")
result = client.bank.send(
wallet=wallet,
to_address=recipient_address,
amount=uakt_amount,
denom="uakt"
)