Class AssociateTokenExtensions
Extension methods for associating tokens with accounts on the network.
Inherited Members
Namespace: Hiero
Assembly: Hiero.dll
Syntax
public static class AssociateTokenExtensions
Methods
| Edit this page View SourceAssociateTokenAsync(ConsensusClient, EntityId, EntityId, Action<IConsensusContext>?)
Provisions Storage associated with the Holder for maintaining token balances for this account.
Declaration
public static Task<TransactionReceipt> AssociateTokenAsync(this ConsensusClient client, EntityId account, EntityId token, Action<IConsensusContext>? configure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ConsensusClient | client | The Consensus Node Client orchestrating the association. |
| EntityId | account | The identifier of the account to provision token balance storage. |
| EntityId | token | The token or NFT token class type to associate with the account. |
| 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 a successful operation. |
Remarks
Since this action will result in higher account renewal costs, it must be signed by the account's key.
Examples
// Associate an account with a token so it can hold a balance. This
// must be signed by the account's key (not the token's admin key).
// Accounts with auto-association slots skip this step.
var receipt = await client.AssociateTokenAsync(account, token);
Console.WriteLine($"Associate 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, for example, if the token has already been associated. |
| 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. |
AssociateTokensAsync(ConsensusClient, AssociateTokenParams, Action<IConsensusContext>?)
Provisions Storage associated with the Holder for maintaining token balances for this account.
Declaration
public static Task<TransactionReceipt> AssociateTokensAsync(this ConsensusClient client, AssociateTokenParams associateParams, Action<IConsensusContext>? configure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ConsensusClient | client | The Consensus Node Client orchestrating the association. |
| AssociateTokenParams | associateParams | The association parameters containing the account and tokens to associate. |
| 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 a successful operation. |
Remarks
Since this action will result in higher account renewal costs, it must be signed by the account's key.
Examples
// Associate several tokens in a single transaction. One transaction
// fee, one signature — cheaper than N separate associations.
var receipt = await client.AssociateTokensAsync(new AssociateTokenParams
{
Account = account,
Tokens = new[] { token1, token2, token3 }
});
Console.WriteLine($"Associate 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, for example, if the token has already been associated. |
| 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. |