Approve an allowance

A transaction that allows a token owner to delegate a token spender to spend the specified token amount on behalf of the token owner. An owner can provide a token allowance for hbars, non-fungible and fungible tokens. The owner is the account that owns the tokens and grants the allowance to the spender. The spender is the account that spends tokens authorized by the owner from the owners account. The spender pays for the transaction fees when transferring tokens from the owners account to another recipient.

The total number of approvals in this transaction cannot exceed 20. Note that each NFT serial number counts as a single approval, hence a transaction granting 20 serial numbers to a spender will use all of the approvals permitted for the transaction.

A single NFT serial number can only be granted to one spender at a time. If an approval assigns a previously approved NFT serial number to a new user, the old user will have their approval removed.

Each account is limited to 100 allowances. This limit spans hbar and fungible token allowances and non-fungible token approved_for_all grants. There is no limit on the number of NFT serial number approvals an owner may grant.

The number of allowances set on an account will increase the auto renewal fee for the account. Conversely, removing allowances will decrease the auto renewal fee for the account.

To decrease the allowance for a given spender, you will need to set the amount to the value you would like to authorize the spender account for. If the spender account was authorized to spend 25 hbars and the owner now wants to modify their allowance to 5 hbars, the owner would submit the AccountAllowanceApproveTransaction for 5 hbars.

Only when a spender is set on an explicit NFT ID of a token, we return the spender ID in theTokenNftInfoQuery for the respective NFT. If approveTokenNftAllowanceAllSerials is used to approve all NFTs for a given token class and no NFT ID is specified, we will not return a spender ID for all the serial numbers of that token.

Transaction Fees

  • Please see the transaction and query fees table for base transaction fee

  • Please use the Hedera fee estimator to estimate your transaction fee cost

Transaction Signing Requirements

  • Must be signed by the owner's account

  • Must be signed by the transaction fee payer if different then the owner account

  • If the owner and transaction fee payer key are the same only one signature is required

Reference: HIP-336

Constructor

Description

new AccountAllowanceApproveTransaction()

Initializes the AccountAllowanceApproveTransaction object

Methods

Method

Type

Description

approveHbarAllowance(<ownerAccountId>,<spenderAccountId>, <amount>)

The owner account ID that is authorizing the allowance, the spender account ID to authorize, the amount of hbar the owner account is authorizing the spender account to use.

approveTokenAllowance(<tokenId>,<ownerAccountId>,<spenderAccountId>, <amount>)

The token ID of the token being granted an allowance by the spender account, the account ID of the owner account, the account ID of the spender account.

approveTokenNftAllowance(<nftId>,<ownerAccountId>, <spenderAccountId>)

The NFT ID of the NFT being granted an allowance by the owner account, the account ID of the owner account, the account ID of the spender account.

approveTokenNftAllowanceAllSerials(<tokenId>,<ownerAccountId>, <spenderAccountId>)

Grant a spender account access to all NFTs in a given token class/collection. The token ID of the NFT collection, the account ID of the owner account, the account ID of the spender account.

//Create the transaction
AccountAllowanceApproveTransaction transaction = new AccountAllowanceApproveTransaction()
    .approveHbarAllowance(ownerAccount, spenderAccountId, Hbar.from(100));

//Sign the transaction with the owner account key and the transaction fee payer key (client)  
TransactionResponse txResponse = transaction.freezeWith(client).sign(ownerAccountKey).execute(client);

//Request the receipt of the transaction
TransactionReceipt receipt = txResponse.getReceipt(client);

//Get the transaction consensus status
Status transactionStatus = receipt.status;

System.out.println("The transaction consensus status is " +transactionStatus);

//v2.12.0+

Last updated