Class AllowanceExtensions
Extension methods for allocating crypto, token, and NFT allowances.
Inherited Members
Namespace: Hiero
Assembly: Hiero.dll
Syntax
public static class AllowanceExtensions
Methods
| Edit this page View SourceAllocateAllowanceAsync(ConsensusClient, AllowanceParams, Action<IConsensusContext>?)
Creates approved allowance(s) allowing the designated spender to spend crypto and tokens from the originating account. Presently the owning account must be the Payer (operator) paying for this transaction when submitted to the network.
Declaration
public static Task<TransactionReceipt> AllocateAllowanceAsync(this ConsensusClient client, AllowanceParams allowanceParams, Action<IConsensusContext>? configure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ConsensusClient | client | The Consensus Node Client orchestrating the update. |
| AllowanceParams | allowanceParams | Parameters containing the list of allowances to create. |
| Action<IConsensusContext> | configure | Optional callback method providing an opportunity to modify the execution configuration for just this method call. It is executed prior to submitting the request to the network. |
Returns
| Type | Description |
|---|---|
| Task<TransactionReceipt> | A transaction receipt indicating success, or an exception is thrown. |
Remarks
This method is also the revocation path for crypto and token
allowances — resubmit with Amount = 0 to revoke, since
HAPI has no dedicated Revoke* transaction for those.
NFT allowances use
RevokeNftAllowanceAsync(ConsensusClient, RevokeNftAllowanceParams, Action<IConsensusContext>?)
instead, for specific serial numbers or, with its
Spender, for an approval for
all of a token's NFTs.
Examples
// Grant `spender` the right to spend up to 5 HBAR from `owner`.
// Owner must be the client's Payer — allowances always originate
// from the transaction payer. Setting Amount = 0 revokes the grant.
var receipt = await client.AllocateAllowanceAsync(new AllowanceParams
{
CryptoAllowances = new[]
{
new CryptoAllowance(owner, spender, 500_000_000) // 5 HBAR
}
});
Console.WriteLine($"Allowance status: {receipt.Status}");
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If required arguments are missing or invalid. |
| InvalidOperationException | If required context configuration is missing. |
| PrecheckException | If the gateway node refused the transaction. Only a code about the transaction itself proves it did not execute; any other code leaves the outcome unknown, so settle it by its transaction id on a mirror node rather than resubmitting it (see PrecheckException). |
| ConsensusException | If the outcome could not be confirmed: the transaction may have executed, so settle it by its transaction id on a mirror node rather than resubmitting it. |
| TransactionException | If the network rejected the request as invalid or had missing data. |