Skip to content

Latest commit

 

History

History
171 lines (124 loc) · 8.06 KB

update-an-account.md

File metadata and controls

171 lines (124 loc) · 8.06 KB

Update an account

A transaction that updates the properties of an existing account. The network will store the latest updates on the account. If you would like to retrieve the state of an account in the past, you can query a mirror node.

Account Properties

{% content-ref url="../../../core-concepts/accounts/account-properties.md" %} account-properties.md {% endcontent-ref %}

Transaction Fees

  • The sender pays for the token association fee and the rent for the first auto-renewal period.
  • Please see the transaction and query fees table for the base transaction fee.
  • Please use the Hedera fee estimator to estimate the cost of your transaction fee.

Transaction Signing Requirements

  • The account key(s) are required to sign the transaction.
  • If you are updating the keys on the account, the OLD KEY and NEW KEY must sign.
    • If either is a key list, the key list keys are all required to sign.
    • If either is a threshold key, the threshold value is required to sign.
  • If you do not have the required signatures, the network will throw an INVALID_SIGNATURE error.

Maximum Auto-Associations and Fees

Accounts have a property, maxAutoAssociations, and the property's value determines the maximum number of automatic token associations allowed.

Property ValueDescription
0Automatic token associations or token airdrops are not allowed, and the account must be manually associated with a token. This also applies if the value is less than or equal to usedAutoAssociations.
-1The number of automatic token associations an account can have is unlimited. -1 is the default value for new automatically-created accounts.
> 0If the value is a positive number (number greater than 0), the number of automatic token associations an account can have is limited to that number.

{% hint style="info" %} The sender pays the maxAutoAssociations fee and the rent for the first auto-renewal period for the association. This is in addition to the typical transfer fees. This ensures the receiver can receive tokens without association and makes it a smoother transfer process. {% endhint %}

Reference: HIP-904

Methods

MethodTypeRequirement
setAccountId(<accountId>)AccountIdRequired
setKey(<key>)KeyOptional
setReceiverSignatureRequired(<boolean>)BooleanOptional
setMaxAutomaticTokenAssociations(<amount>)intOptional
setAccountMemo(<memo>)StringOptional
setAutoRenewPeriod(<duration>)DurationOptional
setStakedAccountId(<stakedAccountId>)AccountIdOptional
setStakedNodeId(<stakedNodeId>)longOptional
setDeclineStakingReward(<declineStakingReward>)booleanOptional
setExpirationTime(<expirationTime>)InstantDisabled

{% tabs %} {% tab title="Java" %}

//Create the transaction to update the key on the account
AccountUpdateTransaction transaction = new AccountUpdateTransaction()
    .setAccountId(accountId)
    .setKey(updateKey);

//Sign the transaction with the old key and new key, submit to a Hedera network   
TransactionResponse txResponse = transaction.freezeWith(client).sign(oldKey).sign(newKey).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);

//Version 2.0.0

{% endtab %}

{% tab title="JavaScript" %}

//Create the transaction to update the key on the account
const transaction = await new AccountUpdateTransaction()
    .setAccountId(accountId)
    .setKey(updateKey)
    .freezeWith(client);

//Sign the transaction with the old key and new key
const signTx = await (await transaction.sign(oldKey)).sign(newKey);

//SIgn the transaction with the client operator private key and submit to a Hedera network
const txResponse = await signTx.execute(client);

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

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

console.log("The transaction consensus status is " +transactionStatus.toString());

//v2.0.5

{% endtab %}

{% tab title="Go" %}

//Create the transaction to update the key on the account
transaction, err := hedera.NewAccountUpdateTransaction().
        SetAccountID(newAccountId).
        SetKey(updateKey.PublicKey()).
        FreezeWith(client)

if err != nil {
    panic(err)
}

//Sign the transaction with the old key and new key, submit to a Hedera network   
txResponse, err := transaction.Sign(newKey).Sign(updateKey).Execute(client)

//Request the receipt of the transaction
receipt, err := txResponse.GetReceipt(client)
if err != nil {
    panic(err)
}

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

println("The transaction consensus status is ", transactionStatus)

//Version 2.0.0

{% endtab %} {% endtabs %}

Get transaction values

Return the properties of an account create transaction.

MethodTypeDescription
getKey()KeyReturns the public key on the account
getInitialBalance()HbarReturns the initial balance of the account
getReceiverSignatureRequired()booleanReturns whether the receiver signature is required or not
getExpirationTime()InstantReturns the expiration time
getAccountMemo()StringReturns the account memo
getDeclineStakingReward()booleanReturns whether or not the account is declining rewards
getStakedNodeId()longReturns the node ID the account is staked to
getStakedAccountId()AccountIdReturns the account ID the node is staked to
getAutoRenewPeriod()DurationReturns the auto renew period on the account

{% tabs %} {% tab title="Java" %}

//Create a transaction
AccountUpdateTransaction transaction = new AccountUpdateTransaction()
    .setAccountId(accountId)
    .setKey(newKeyUpdate);

//Get the key on the account
Key accountKey = transaction.getKey();

//v2.0.0

{% endtab %}

{% tab title="JavaScript" %}

//Create a transaction
const transaction = new AccountUpdateTransaction()
    .setAccountId(accountId)
    .setKey(newKeyUpdate);

//Get the key of an account
const accountKey = transaction.getKey();

//v2.0.0

{% endtab %}

{% tab title="Go" %}

//Create the transaction 
transaction, err := hedera.NewAccountUpdateTransaction().
        SetAccountID(newAccountId).
        SetKey(updateKey.PublicKey())

//Get the key of an account
accountKey := transaction.GetKey()

//v2.0.0

{% endtab %} {% endtabs %}