Skip to content

Authz module

The authz module provides functionality for authorization grants, allowing one account to execute transactions on behalf of another account.

Transaction parameters

All transaction functions support optional parameters like fee_amount, gas_limit, and gas_adjustment. See Transaction parameters for details.

AuthzClient class

from akash import AkashClient

client = AkashClient("https://akash-rpc.polkachu.com:443")

authz = client.authz

Transactions

grant_authorization()

Grant authorization to another account to execute specific transaction types.

def grant_authorization(wallet, grantee: str, msg_type_url: str = "/cosmos.bank.v1beta1.MsgSend",
                        spend_limit: str = "1000000000", denom: str = "uakt",
                        authorization_type: str = "send", expiration_days: int = 30,
                        memo: str = "", fee_amount: str = None, gas_limit: int = None,
                        gas_adjustment: float = 1.2, use_simulation: bool = True) -> BroadcastResult

Required parameters:

  • wallet (AkashWallet): Granter's wallet
  • grantee (str): Address to grant authorization to

Optional parameters:

  • msg_type_url (str): Message type to authorize (default: "/cosmos.bank.v1beta1.MsgSend")
  • spend_limit (str): Maximum amount the grantee can spend (default: "1000000000")
  • denom (str): Token denomination (default: "uakt")
  • authorization_type (str): Type of authorization - "send" or "generic" (default: "send")
  • expiration_days (int): Days until grant expires (default: 30)
  • 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)
  • use_simulation (bool): Enable gas simulation (default: True)

Returns: BroadcastResult - Transaction result with the following fields:

  • tx_hash (str): Transaction hash
  • code (int): Response code (0 for success)
  • raw_log (str): Raw transaction log/error message
  • success (bool): Whether transaction succeeded
  • events (List[Dict]): Transaction events
    • type (str): Event type
    • attributes (List[Dict]): Event attributes
      • key (str): Attribute key
      • value (str): Attribute value

Example:

from akash import AkashClient, AkashWallet

granter_wallet = AkashWallet.from_mnemonic("granter mnemonic")
client = AkashClient("https://akash-rpc.polkachu.com:443")

result = client.authz.grant_authorization(
    wallet=granter_wallet,
    grantee="akash1grantee...",
    msg_type_url="/cosmos.bank.v1beta1.MsgSend",
    authorization_type="send",
    spend_limit="1000000",
    denom="uakt",
    expiration_days=90
)

if result.success:
    print(f"Authorization granted: {result.tx_hash}")

revoke_authorization()

Revoke previously granted authorization.

def revoke_authorization(wallet, grantee: str, msg_type_url: str,
                         memo: str = "", fee_amount: str = None, gas_limit: int = None,
                         gas_adjustment: float = 1.2, use_simulation: bool = True) -> BroadcastResult

Required parameters:

  • wallet (AkashWallet): Granter's wallet
  • grantee (str): Address to revoke authorization from
  • msg_type_url (str): Message type to revoke authorization for

Optional parameters:

  • 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)
  • use_simulation (bool): Enable gas simulation (default: True)

Returns: BroadcastResult - Transaction result with the following fields:

  • tx_hash (str): Transaction hash
  • code (int): Response code (0 for success)
  • raw_log (str): Raw transaction log/error message
  • success (bool): Whether transaction succeeded
  • events (List[Dict]): Transaction events
    • type (str): Event type
    • attributes (List[Dict]): Event attributes
      • key (str): Attribute key
      • value (str): Attribute value

Example:

from akash import AkashClient, AkashWallet

client = AkashClient("https://akash-rpc.polkachu.com:443")
granter_wallet = AkashWallet.from_mnemonic("granter mnemonic here")

result = client.authz.revoke_authorization(
    wallet=granter_wallet,
    grantee="akash1grantee...",
    msg_type_url="/cosmos.bank.v1beta1.MsgSend"
)

execute_authorized()

Execute transactions using granted authorization.

def execute_authorized(wallet, messages: List[Dict[str, Any]],
                       memo: str = "", fee_amount: str = None, gas_limit: int = None,
                       gas_adjustment: float = 1.2, use_simulation: bool = True) -> BroadcastResult

Required parameters:

  • wallet (AkashWallet): Grantee's wallet
  • messages (List[Dict[str, Any]]): Messages to execute on behalf of granter

Optional parameters:

  • 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)
  • use_simulation (bool): Enable gas simulation (default: True)

Returns: BroadcastResult - Transaction result with the following fields:

  • tx_hash (str): Transaction hash
  • code (int): Response code (0 for success)
  • raw_log (str): Raw transaction log/error message
  • success (bool): Whether transaction succeeded
  • events (List[Dict]): Transaction events
    • type (str): Event type
    • attributes (List[Dict]): Event attributes
      • key (str): Attribute key
      • value (str): Attribute value

Example:

from akash import AkashClient, AkashWallet

client = AkashClient("https://akash-rpc.polkachu.com:443")
grantee_wallet = AkashWallet.from_mnemonic("grantee mnemonic")

messages = [{
    "@type": "/cosmos.bank.v1beta1.MsgSend",
    "from_address": "akash1granter...",
    "to_address": "akash1recipient...",
    "amount": [{"denom": "uakt", "amount": "500000"}]
}]

result = client.authz.execute_authorized(
    wallet=grantee_wallet,
    messages=messages
)

Queries

get_grants()

Query authorization grants between accounts.

def get_grants(granter: str, grantee: str = "", msg_type_url: str = "") -> List[Dict[str, Any]]

Required parameters:

  • granter (str): Granter address

Optional parameters:

  • grantee (str): Grantee address (default: "")
  • msg_type_url (str): Message type URL to filter by (default: "")

Returns: List[Dict[str, Any]] - List of authorization grants with the following fields:

  • authorization (Dict): Authorization details
    • @type (str): Authorization type URL
    • spend_limit (List[Dict]): Spending limits for SendAuthorization
      • denom (str): Token denomination
      • amount (str): Maximum amount
    • msg (str): Message type for GenericAuthorization
  • expiration (Dict): Grant expiration details
    • seconds (int): Expiration timestamp in seconds
    • nanos (int): Additional nanoseconds

Example:

from akash import AkashClient

client = AkashClient("https://akash-rpc.polkachu.com:443")

grants = client.authz.get_grants("akash1granter...")

for grant in grants:
    print(f"Authorization: {grant['authorization']['@type']}")
    print(f"Expiration: {grant['expiration']['seconds']}")

get_granter_grants()

Get all grants issued by a specific granter.

def get_granter_grants(granter: str) -> List[Dict[str, Any]]

Required parameters:

  • granter (str): Granter address

Returns: List[Dict[str, Any]] - List of authorization grants with the following fields:

  • granter (str): Address of the account that granted authorization
  • grantee (str): Address of the account that received authorization
  • authorization (Dict): Authorization details
    • @type (str): Authorization type URL
    • spend_limit (List[Dict]): Spending limits for SendAuthorization
      • denom (str): Token denomination
      • amount (str): Maximum amount
    • msg (str): Message type for GenericAuthorization
  • expiration (Dict): Grant expiration details
    • seconds (int): Expiration timestamp in seconds
    • nanos (int): Additional nanoseconds

Example:

from akash import AkashClient

client = AkashClient("https://akash-rpc.polkachu.com:443")

granter_grants = client.authz.get_granter_grants("akash1granter...")

print(f"Granter has issued {len(granter_grants)} authorizations:")
for grant in granter_grants:
    print(f"To: {grant['grantee']}")
    print(f"Type: {grant['authorization']['@type']}")

get_grantee_grants()

Get all grants received by a specific grantee.

def get_grantee_grants(grantee: str) -> List[Dict[str, Any]]

Required parameters:

  • grantee (str): Grantee address

Returns: List[Dict[str, Any]] - List of authorization grants with the following fields:

  • granter (str): Address of the account that granted authorization
  • grantee (str): Address of the account that received authorization
  • authorization (Dict): Authorization details
    • @type (str): Authorization type URL
    • spend_limit (List[Dict]): Spending limits for SendAuthorization
      • denom (str): Token denomination
      • amount (str): Maximum amount
    • msg (str): Message type for GenericAuthorization
  • expiration (Dict): Grant expiration details
    • seconds (int): Expiration timestamp in seconds
    • nanos (int): Additional nanoseconds

Example:

from akash import AkashClient

client = AkashClient("https://akash-rpc.polkachu.com:443")

my_grants = client.authz.get_grantee_grants("akash1mywallet...")

print(f"You have {len(my_grants)} authorizations:")
for grant in my_grants:
    print(f"From: {grant['granter']}")
    print(f"Can execute: {grant['authorization']['@type']}")