Skip to content

Latest commit

 

History

History
157 lines (134 loc) · 5.11 KB

File metadata and controls

157 lines (134 loc) · 5.11 KB

Create an account

The account represents your account specific to the Hedera network. Accounts are required to utilize the Hedera network services and to pay network transaction fees.

{% hint style="info" %} When creating a new account an existing account will need to fund the initial balance and pay for the transaction fee. {% endhint %}

Constructor Description
AccountCreateTransaction() Initializes the AccountCreateTransaction object
new AccountCreateTransaction()

Basic

Method Type Description
setKey(<key>) Ed25519 The public key generated for the new account.
setInitialBalance(<initialBalance>) Hbar/long Set the initial balance of the account, transferred from the operator account, in tinybar.

Example:

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

Transaction tx = new AccountCreateTransaction()
     // The only _required_ property here is `key`
     .setKey(newKey.PublicKey())
     .setInitialBalance(1000)
     .setMaxTransactionFee(Hbar.fromTinybar(1000))
     .build(client);

tx.execute(client);

// This will wait for the receipt to become available
TransactionReceipt receipt = tx.getReceipt(client);

AccountId newAccountId = receipt.getAccountId();

System.out.println("account = " + newAccountId);

{% endtab %}

{% tab title="JavaScript" %}

const { Client, Ed25519PrivateKey, AccountCreateTransaction } = require("@hashgraph/sdk");
require("dotenv").config();

async function main() {
    const operatorPrivateKey = process.env.OPERATOR_KEY;
    const operatorAccount = process.env.OPERATOR_ID;

    if (operatorPrivateKey == null || operatorAccount == null) {
        throw new Error("environment variables OPERATOR_KEY and OPERATOR_ID must be present");
    }

    const client = new Client({
        network: { "0.testnet.hedera.com:50211": "0.0.3" },
        operator: {
            account: operatorAccount,
            privateKey: operatorPrivateKey
        }
    });

    const privateKey = await Ed25519PrivateKey.generate();

    console.log("Automatic signing example");
    console.log(`private = ${privateKey.toString()}`);
    console.log(`public = ${privateKey.publicKey.toString()}`);

    const transactionId = await new AccountCreateTransaction()
        .setKey(privateKey.publicKey)
        .setInitialBalance(0)
       // .setGenerateRecord Available in the JS SDK but not in the JAVA SDK
        .execute(client);

    const transactionReceipt = await transactionId.getReceipt(client);
    const newAccountId = transactionReceipt.getAccountId();

    console.log(`account = ${newAccountId}`);
    }
main();

{% endtab %} {% endtabs %}

Advanced

Methods Type Description
setAutoRenewPeriod(<autoRenewPeriod>) Duration

The period of time in which the account will auto-renew in seconds. The account is charged tinybars for every auto-renew period. Duration type is in seconds. For example, one hour would result in the input value of 3,600 seconds.NOTE: This is fixed to approximately 3 months (7890000 seconds). Any other value will return the following error: AUTORENEW_DURATION_NOT_IN_RANGE.

default: 2,592,000 seconds

setReceiverSignatureRequired(<booleanValue>) boolean

If true, all the account keys must sign any transaction depositing into this account (in addition to all withdrawals)

default: false

setReceiveRecordThreshold(<receiveRecordThreshold>) Hbar/long

Creates a record for any transaction that deposits more than x value of tinybars.

Note: You will incur a charge each time the record is generated.

setSendRecordThreshold(<sendRecordThreshold>) Hbar/long

Creates a record for any transaction that withdraws more than x value of tinybars.

Note: You will incur a charge each time the record is generated.

setProxyAccount(<accountId>) AccountID ID of the account to which this account is proxy staked