Setup
Setup tutorial - HSCS workshop. Learn how to enable custom logic & processing on Hedera through smart contracts.
Last updated
Setup tutorial - HSCS workshop. Learn how to enable custom logic & processing on Hedera through smart contracts.
Last updated
The setup has already been (mostly) done. All that's left for you to do is clone the accompanying tutorial GitHub repository and install the dependencies:
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 .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.
Visit the Hedera Portal to get started.
(1) Create a Testnet account.
(2) Copy-paste the confirmation code sent to your email.
(3) Fill out this form with details for your profile.
(4) In the top-left there is a drop down menu, select between Hedera Testnet (default) and Previewnet:
(5) From the next screen that shows your accounts, copy the value of the "DER-encoded private key" and replace OPERATOR_KEY
in the .env
file with it.
(6) From the same screen, copy the value of "Account ID" and replace the value of the OPERATOR_ID
variable in the .env
file 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.
To do so, we will utilise something called a seed phrase, which is a sequence of selected dictionary words chosen at random. This process is defined in BIP-39.
Subsequently, we will use that seed phrase as an input and generate multiple accounts; each of which consists of a private key, a public key, and an address. This process is defined in BIP-44.
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).
Enough theory - let's generate a seed phrase!
Visit iancoleman.io/bip39
, and you can generate a BIP39 seed phrase there: `
`
Locate the line that is labelled "Generate a random mnemonic"
Select any number from the dropdown that is more than or equal to 12
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_PHRASE
variable in the .env
file 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 intro
directory, 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 generate-evm-accounts.js
.
Run this script.
This should output something similar to the following:
Copy the HashScan URL, paste it into a browser, and you will see a "Transaction" page on HashScan.
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.00000000
to 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 0.00185217
as above.)
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: 0.0.3996280
.
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:
Run your own Hedera RPC Relay server: Configuring Hedera JSON-RPC Relay endpoints
Use an RPC service provider, Arkhia: Configuring Arkhia RPC endpoints
Whichever method you choose, obtain the JSON-RPC URL for Hedera Testnet, and replace the value of the RPC_URL_HEDERATESTNET
variable in the .env
file with this.