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 agent 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 TransactionId record indicating success, or an exception is thrown. |
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 |
|---|---|
| ArgumentOutOfRangeException | If required arguments are missing. |
| InvalidOperationException | If required context configuration is missing. |
| PrecheckException | If the gateway node rejected the request upon submission. |
| ConsensusException | If the network was unable to come to consensus before the duration of the transaction expired. |
| TransactionException | If the network rejected the request as invalid or had missing data. |