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.
Last updated
Was this helpful?
Hello World sequence: Create a new account on Hedera Testnet, and fund it. Do this before any of the other Hello World sequences.
Last updated
Was this helpful?
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 micro-transactions. On Hedera, this currency is HBAR.
Before you begin, you should be familiar with the following:
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.
In the terminal, from the hello-future-world
directory, enter the subdirectory for this sequence.
Install the dependencies using npm
.
Make a .env
file by copying the provided .env.sample
file. Then open the .env
file in a code editor, such as VS Code.
In the terminal, run the following command:
This should output a seed phrase, a list of 12 randomly selected dictionary words, for example:
Copy the seed phrase. Replace SEED_PHRASE
in the .env
file with it. The file contents should now look similar to this:
You do not need to modify the other values in the .env
file yet.
Be sure to save your files before moving on to the next step.
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.
Open the script file, script-create-fund-account.js
, in a code editor.
The hdNodeRoot
instance is subsequently used to generate the private keys.
A privateKey
instance has been initialized. This requires no further input to derive an EVM address - read its publicKey
property, and then invoke its toEvmAddress
method:
In the terminal, run the script using the following command:
This should produce output similar to the following:
Note that accountId
and accountBalanceHbar
are both undefined
, because generating cryptographic keys alone is not enough to create an account - that only happens upon the first transaction.
Copy the value of privateKeyHex
. Replace YOUR_HEX_ENCODED_PRIVATE_KEY
in the .env
file with it. The file contents should now look similar to this:
Copy the value of accountExplorerUrl
and visit this in your browser.
You should see a page with:
The title "Inactive EVM Address" (1)
"Account ID: Assigned upon activation" (2)
"EVM Address:" matching the value of evmAddress
output earlier (3)
A helpful hint saying "Own this account? Activate it by transferring any amount of ℏ or tokens to ..." (4)
This is precisely the next step!
Paste the value of evmAddress
output earlier into the "enter wallet address" field (1)
Press the "receive testnet HBAR" button (2)
A confirmation dialog will pop up.
Complete the ReCaptcha (1)
Press the "confirm transaction" button. (2)
A success dialog will pop up.
The account ID is displayed (1)
This indicates that the Testnet HBAR has been transferred, and in the process a new account has been created.
Note that the EVM address is not the same as the account ID - instead the EVM address is an alias of the account ID.
Press the icon to copy the account ID (2)
Replace YOUR_ACCOUNT_ID
in the .env
file with it. The file contents should now look similar to this:
Refresh the Hashscan page in your browser. Note that this is the accountExplorerUrl
that was output from the previous run of the script. This time you should see:
The title is "Account" (1)
instead of "Inactive EVM Address"
The "Account ID" field should matching the value of ACCOUNT_ID
above (2)
instead of "Assigned upon activation"
The "Create Transaction" field displays a transaction ID (3)
In the terminal, re-run the script using the following command:
This should produce output similar to the following:
Note that this is almost the same as when you first ran the same script. The difference is that previously both accountId
and accountBalanceHbar
were undefined
; and now accountId
should now show a value (in the format of 0.0.XYZ
), and accountBalanceHbar
should now show a number (with 8 decimal places). This is because the account has been created and funded.
🎉 Now you are ready to start using your Hedera Testnet account from the portal within script files on your computer! 🎉
Congratulations, you have completed the create and fund account Hello World sequence! 🎉🎉🎉
You have learned how to:
If you have to work with git
, you may wish use this command instead:
Visit
Note that is a tool that generates , and your seed phrase will be different from above.
The ethersHdNode
module has been imported from . This takes a seed phrase as input, and outputs a private key. To do so, invoke the fromMnemonic()
method and pass in process.env.SEED_PHRASE
as the parameter:
Visit .
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 repo, , is intended to be used alongside this tutorial.
Alternatively, you may view the completed
branch on Github:
Writer: Editors: , , ,