Comment on page
Setup tutorial - HSCS workshop. Learn how to enable custom logic & processing on Hedera through smart contracts.
Hedera Smart Contract Service Workshop Part 2/6 | Setup
If you do not have SSH available on your system, or are unable to configure it for GitHub, you may wish to try this git command instead:
git clone -b main https://github.com/hedera-dev/hedera-smart-contracts-workshop.git
In the root directory of the repo, you will find a file named
.env.example. Make a copy of this file, and name it
cp .env.example .env
An operator account is used to obtain an initial sum of HBAR on Hedera Testnet, and then use that to pay for various Hedera network operations. This includes everything from basic transactions, to gas fees for HSCS interactions.
(1) Create a Testnet account.
Hedera Portal - Create Testnet Account
(2) Copy-paste the confirmation code sent to your email.
Hedera Portal - Email Verification
(3) Fill out this form with details for your profile.
Hedera Portal - Profile Details
(4) In the top-left there is a drop down menu, select between Hedera Testnet (default) and Previewnet:
Hedera Portal - Select Network
(5) From the next screen that shows your accounts, copy the value of the "DER-encoded private key" and replace
.envfile with it.
Hedera Portal - Account Details
(6) From the same screen, copy the value of "Account ID" and replace the value of the
OPERATOR_IDvariable in the
.envfile with it.
Note that private keys should be stored and managed securely. For the purposes of a tutorial, secure key management has been skipped, and you are storing your private keys in plain text on disk. Do not do this in production applications.
When developing smart contracts, you often need more than 1 account to do so. Thankfully we do not need to go through the somewhat cumbersome process of creating multiple accounts via the Hedera Portal - you only really need to do that once for the operator account.
Any subsequent accounts that you wish to create can be generated programmatically, and funded with HBAR from your operator account.
Interestingly these 2 BIPs were never adopted by the Bitcoin community, but are almost de-facto used by everyone in the Ethereum community. On Hedera, you can use these 2 BIPs to generate Hedera EVM accounts, but this is not possible for Hedera-native accounts (as they use a different type of public key algorithm).
ECDSA (Elliptic Curve Digital Signing Algorithm) is a public key algorithm, and secp256k1 is a particular configuration that may be used by the ECDSA algorithm.
EdDSA (Edwards Digital Signing Algorithm) is another public key algorithm, and Ed25519 is a particular configuration that may be used by the EdDSA algorithm.
Both Bitcoin and Ethereum use ECDSA with secp256k1 for their accounts.
Hedera native accounts use EdDSA with Ed25519, and Hedera EVM accounts use ECDSA with secp256k1.
Enough theory - let's generate a seed phrase!
- Locate the line that is labelled "Generate a random mnemonic"
- Select any number from the dropdown that is more than or equal to
- Press "GENERATE"
- Locate the section that is labelled "BIP39 Mnemonic"
- Copy these words from the text box - this will be your BIP39 seed phrase
Replace the value of the
BIP39_SEED_PHRASEvariable in the
.envfile with this phrase.
At this point, you have an operator account, which is already funded with HBAR, and you have a seed phrase. Let's generate more accounts based on the seed phrase , and then transfer HBAR to them from the operator account.
First switch to the
introdirectory, and install dependencies using npm.
Next, let's use a script already prepared for you. We want this script to generate 2 Hedera EVM accounts, and transfer 100 HBAR to each of them, so let's set those values in
const NUM_ACCOUNTS = 2;
const AMOUNT_PER_ACCOUNT = 100;
const HD_PATH = "m/44'/60'/0'/0";
Run this script.
This should output something similar to the following:
EVM account #0 generated.
#0 HD path: m/44'/60'/0'/0/0
#0 Private key: 3030020100300706052b8104000a04220420fb11afc5d508036ac7a9df9f1eb7cea551e4a7b738c2c70da099fe5f379f3364
#0 Public key: 302d300706052b8104000a032200027a753c29cc9f0ea0b6ccf0614676daeba3da0dbd5f54ef9850ad3878ded4e077
#0 EVM address: 07ffaadfe3a598b91ee08c88e5924be3eff35796
EVM account #1 generated.
#1 HD path: m/44'/60'/0'/0/1
#1 Private key: 3030020100300706052b8104000a042204206e3ff9f1f1ae58248a5838ec877acc55d103009586224d76ab74a652d408cf12
#1 Public key: 302d300706052b8104000a03220002c4c2ed7a682a601c9c61dec42e87442b63893a6e5efdf6dc327a4b3bcc62aba9
#1 EVM address: 1c29e31d241f0d06f3763221f5224a6b82f09cce
Transfer transaction ID: [email protected]
HashScan URL: https://hashscan.io/testnet/transaction/[email protected]
Copy the HashScan URL, paste it into a browser, and you will see a "Transaction" page on HashScan.
Screenshot showing a single transaction with multiple recipients transferring HBAR (on hashscan.io).
Scroll down to the "Transfers" section, which should show the flow of HBAR between various accounts. In this case
-200(and a fractional amount of
-0.00185217) from the operator account,
+100.00000000to each of the 2 EVM accounts, and fractional amounts to a couple of other accounts to pay for transaction processing. (Note that the fractional amounts may vary, they won't necessarily be
Now you should have 1 Hedera-native account (previously funded), plus 2 new EVM accounts (freshly funded).
Hedera networks have a native account address format, called the Account ID. An example of this would be:
Hedera also supports EVM account address formats. This has 2 variants:
The EVM Address Alias. An example of this would be:
0x7394111093687e9710b7a7aeba3ba0f417c54474. This is sometimes referred to as the non-long-zero address.
The Account Num Alias. An example of this would be:
0x00000000000000000000000000000000003cfa78. This is sometimes referred to as the long-zero address.
Finally Hedera also supports a Key Alias, and this is something that you're unlikely to encounter in most situations.
While you may choose to interact with the Hedera network using any of the address formats, when interacting with smart contracts, the EVM Address Alias is the most useful, as that is what is visible and understood by smart contracts when they are invoked.
For this step, you have a choice:
Whichever method you choose, obtain the JSON-RPC URL for Hedera Testnet, and replace the value of the
RPC_URL_HEDERATESTNETvariable in the
.envfile with this.