Feegrant module¶
The feegrant module provides fee grant management functionality for the Akash Network, allowing accounts to pay transaction fees on behalf of other accounts.
Transaction parameters
All transaction functions support flexible parameters. See Transaction parameters for details on available options like fee_amount
, gas_limit
, and gas_adjustment
.
FeegrantClient Class¶
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
feegrant = client.feegrant
Transactions¶
grant_allowance()¶
Grants a fee allowance to another account, allowing them to spend the granter's tokens for transaction fees.
def grant_allowance(wallet, grantee: str, allowance_type: str = "basic",
spend_limit: str = "1000000", denom: str = "uakt",
expiration: Optional[str] = None, period_seconds: int = 86400,
memo: str = "", fee_amount: str = None, gas_limit: int = None,
gas_adjustment: float = 1.2, use_simulation: bool = True) -> BroadcastResult
Required parameters:
wallet
(Wallet
): Wallet to sign the transaction (granter)grantee
(str
): Address of the account receiving the allowance
Optional parameters:
allowance_type
(str
): Type of allowance (default: "basic")spend_limit
(str
): Maximum amount that can be spent in base units (default: "1000000")denom
(str
): Token denomination (default: "uakt")expiration
(str
): Expiration time in RFC3339 format (default: None)period_seconds
(int
): Period duration in seconds for periodic allowance (default: 86400)memo
(str
): Transaction memo (default: "")fee_amount
(str
): Fee amount in base units (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 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
Note: Supports both "basic" and "periodic" allowance types. For periodic allowances, the period spend limit is automatically calculated as 10% of the total spend limit with the specified period duration.
Example:
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic phrase here")
result = client.feegrant.grant_allowance(
wallet=wallet,
grantee="akash1j8s87w3fctz7nlcqtkl5clnc805r240443eksx",
allowance_type="basic",
spend_limit="5000000",
denom="uakt"
)
print(f"TX hash: {result.tx_hash}")
print(f"Success: {result.success}")
revoke_allowance()¶
Revokes a previously granted fee allowance from another account.
def revoke_allowance(wallet, grantee: str, memo: str = "",
fee_amount: str = None, gas_limit: int = None,
gas_adjustment: float = 1.2, use_simulation: bool = True) -> BroadcastResult
Required parameters:
wallet
(Wallet
): Wallet to sign the transaction (granter)grantee
(str
): Address of the account losing the allowance
Optional parameters:
memo
(str
): Transaction memo (default: "")fee_amount
(str
): Fee amount in base units (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 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 mnemonic phrase here")
result = client.feegrant.revoke_allowance(
wallet=wallet,
grantee="akash1j8s87w3fctz7nlcqtkl5clnc805r240443eksx"
)
print(f"TX hash: {result.tx_hash}")
print(f"Revoked: {result.success}")
Queries¶
get_allowance()¶
Queries the fee allowance between a specific granter and grantee pair.
Required parameters:
granter
(str
): Address of the account that granted the allowancegrantee
(str
): Address of the account that received the allowance
Returns: Dict
- Fee allowance information with the following fields:
granter
(str
): Address of the grantergrantee
(str
): Address of the granteeallowance
(Dict
): Allowance details with:type_url
(str
): Type identifier of the allowance
Note: Returns an empty dictionary if no allowance exists between the specified accounts.
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
allowance = client.feegrant.get_allowance(
granter="akash1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4",
grantee="akash1j8s87w3fctz7nlcqtkl5clnc805r240443eksx"
)
if allowance:
print(f"Granter: {allowance['granter']}")
print(f"Grantee: {allowance['grantee']}")
print(f"Type: {allowance['allowance']['type_url']}")
else:
print("No allowance found")
get_allowances()¶
Queries all fee allowances granted to a specific grantee account.
def get_allowances(grantee: str, limit: int = 100, offset: int = 0, count_total: bool = False) -> List[Dict[str, Any]]
Required parameters:
grantee
(str
): Address of the account that received allowances
Optional parameters:
limit
(int
): Maximum number of results to return (default: 100)offset
(int
): Number of results to skip (default: 0)count_total
(bool
): Include total count in response (default: False)
Returns: List[Dict]
- List of fee allowances, each containing:
granter
(str
): Address of the grantergrantee
(str
): Address of the granteeallowance
(Dict
): Allowance details with:type_url
(str
): Type identifier of the allowance
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
allowances = client.feegrant.get_allowances(
grantee="akash1j8s87w3fctz7nlcqtkl5clnc805r240443eksx"
)
paginated_allowances = client.feegrant.get_allowances(
grantee="akash1j8s87w3fctz7nlcqtkl5clnc805r240443eksx",
limit=20,
offset=10
)
for allowance in allowances:
print(f"From: {allowance['granter']}")
print(f"Type: {allowance['allowance']['type_url']}")
print("---")
get_allowances_by_granter()¶
Queries all fee allowances granted by a specific granter account.
def get_allowances_by_granter(granter: str, limit: int = 100, offset: int = 0, count_total: bool = False) -> List[Dict[str, Any]]
Required parameters:
granter
(str
): Address of the account that granted allowances
Optional parameters:
limit
(int
): Maximum number of results to return (default: 100)offset
(int
): Number of results to skip (default: 0)count_total
(bool
): Include total count in response (default: False)
Returns: List[Dict]
- List of fee allowances granted, each containing:
granter
(str
): Address of the grantergrantee
(str
): Address of the granteeallowance
(Dict
): Allowance details with:type_url
(str
): Type identifier of the allowance
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
granted = client.feegrant.get_allowances_by_granter(
granter="akash1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4"
)
paginated_granted = client.feegrant.get_allowances_by_granter(
granter="akash1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4",
limit=50,
offset=0,
count_total=True
)
for allowance in granted:
print(f"To: {allowance['grantee']}")
print(f"Type: {allowance['allowance']['type_url']}")
print("---")
Utils¶
create_basic_allowance()¶
Creates a basic allowance dictionary structure for use in grant operations.
def create_basic_allowance(spend_limit: str, denom: str = "uakt",
expiration: str = None) -> Dict[str, Any]
Required parameters:
spend_limit
(str
): Maximum amount that can be spent in base units
Optional parameters:
denom
(str
): Token denomination (default: "uakt")expiration
(str
): Expiration time in RFC3339 format (default: None)
Returns: Dict
- Basic allowance structure with:
@type
(str
): Type URL for BasicAllowancespend_limit
(List[Dict]
): Spending limit with denom and amountdenom
(str
): Token denominationamount
(str
): Maximum amount
expiration
(str
): Expiration timestamp if provided
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
allowance = client.feegrant.create_basic_allowance(
spend_limit="1000000",
denom="uakt",
expiration="2024-12-31T23:59:59Z"
)
print(f"Type: {allowance['@type']}")
print(f"Limit: {allowance['spend_limit'][0]['amount']} {allowance['spend_limit'][0]['denom']}")
create_periodic_allowance()¶
Creates a periodic allowance dictionary structure for use in grant operations.
def create_periodic_allowance(total_limit: str, period_limit: str,
period_seconds: int, denom: str = "uakt") -> Dict[str, Any]
Required parameters:
total_limit
(str
): Total spend limit in base unitsperiod_limit
(str
): Amount that can be spent per period in base unitsperiod_seconds
(int
): Period duration in seconds
Optional parameters:
denom
(str
): Token denomination (default: "uakt")
Returns: Dict
- Periodic allowance structure with:
@type
(str
): Type URL for PeriodicAllowancebasic
(Dict
): Basic allowance containing total spend limitperiod
(Dict
): Period duration with seconds and nanosperiod_spend_limit
(List[Dict]
): Per-period spending limitdenom
(str
): Token denominationamount
(str
): Maximum amount per period
Example:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
allowance = client.feegrant.create_periodic_allowance(
total_limit="10000000",
period_limit="1000000",
period_seconds=86400,
denom="uakt"
)
print(f"Type: {allowance['@type']}")
print(f"Total: {allowance['basic']['spend_limit'][0]['amount']}")
print(f"Per period: {allowance['period_spend_limit'][0]['amount']}")