Create and fund account
Hello World sequence: Create a new account on Hedera Testnet, and fund it. Do this before any of the other Hello World sequences.
Why you need to create and fund an account
Hedera is a distributed ledger technology (DLT). To interact with it, you will need to send transactions to the network, which will then process them and add them to the ledger if they are deemed to be valid. On most web services (web2), you need to authenticate using usernames and passwords to operate your account. On DLTs such as Hedera, it is similar, except that you will need to use cryptographic keys instead of passwords to operate your account. One key difference is that unlike web2, each interaction needs to be paid for using the native currency of the DLT, which is similar to microtransactions. On Hedera, this currency is HBAR.
What you will accomplish
Prerequisites
Before you begin, you should be familiar with the following:
Get started: Set up project
To follow along, start with the main
branch, which is the default branch of this repo. This gives you the initial state from which you can follow along with the steps as described in the tutorial.
git clone https://github.com/hedera-dev/hello-future-world.git
In the terminal, from the hello-future-world
directory, enter the subdirectory for this sequence.
cd 00-create-fund-account/
Install the dependencies using npm
.
npm install
Create your .env file
Make a .env
file by copying the provided .env.sample
file. Then open the .env
file in a code editor, such as VS Code.
cp .env.sample .env
Create account
If you already have an account on the Hedera Portal, you may skip the following steps.
Once your portal testnet account is created, copy the Hedera Testnet Account ID and HEX-encoded private key from your Hedera portal dashboard (see screenshot below) and assign them to the MY_ACCOUNT_ID
and MY_PRIVATE_KEY
variables in your .env
file:

For example, if your Account ID is 0.0.123
, and your HEX-encoded private key is 0xabcd1234
, your .env
file should look like this:
ACCOUNT_ID=0.0.123
ACCOUNT_PRIVATE_KEY=0xabcd1234
🎉 Now you are ready to start using your Hedera Testnet account from the portal within script files on your computer! Be sure to save your files before moving on to the next step.
Write the script
An almost complete script has already been prepared for you, and you will only need to make a few modifications (outlined below) for it to run successfully.
Then open the script file, script-create-fund-account.js
, in a code editor.
Step 1: Initialize the account using Client
Client
Initialize the client
instance by invoking the setOperator
method, and passing in accountId
and accountKey
as parameter.
const client = Client.forTestnet().setOperator(accountId, accountKey);
Now the client
instance represents and operates your account.
Step 2: Obtain the balance of the account
Use the AccountBalanceQuery
method to obtain the Testnet HBAR balance of your account.
const accountBalance = await new AccountBalanceQuery()
Note: The return value is an object and needs to be parsed.
Step 3: Convert the balance result object to HBARs
Parse that return value to extract its Testnet HBAR balance so that you may convert it into a string for display purposes.
const accountBalanceHbars = accountBalance.hbars.toBigNumber();
Run the script
In the terminal, run the script using the following command:
node script-create-fund-account.js
You should see output similar to the following:
accountId: 0.0.1201
accountBalanceTinybars: 10,000.00000000
accountExplorerUrl: https://hashscan.io/testnet/account/0.0.1201
Open accountExplorerUrl
in your browser and check that:
The account exists, and its "account ID" should match
accountId
.The "balances" should match
accountBalanceTinybars
.
Complete
Congratulations, you have completed the create and fund account Hello World sequence! 🎉🎉🎉
You have learned how to:
Next Steps
Now that you have an account on Hedera Testnet and it is funded, you can interact with the Hedera network. Continue by following along with the other Hello World sequences.
Cheat sheet
Last updated
Was this helpful?