Environment Setup
Summary
This environment setup guide will provide you with the necessary steps to get your development environment ready for building applications on the Hedera Network. You will set up a new project directory, establish a .env
environment variable file to store your Hedera Testnet account ID and private keys and configure your Hedera Testnet client.
Prerequisites
Completed the Introduction step.
Step 1: Create your project directory
Open your IDE of choice and follow the below steps to create your new project directory.
Create a new Gradle project and name it HederaExamples
. Add the following dependencies to your build.gradle
file.
dependencies {
implementation 'com.hedera.hashgraph:sdk:2.29.0'
implementation 'io.grpc:grpc-netty-shaded:1.46.0'
implementation 'io.github.cdimascio:dotenv-java:2.3.2'
implementation 'org.slf4j:slf4j-nop:2.0.3'
implementation 'com.google.code.gson:gson:2.8.8'
}
Step 2: Install Dependencies and SDKs
Create a new Java class and name it something like HederaExamples
. Import the following classes to use in your example:
import com.hedera.hashgraph.sdk.AccountId;
import com.hedera.hashgraph.sdk.Client;
import com.hedera.hashgraph.sdk.PrivateKey;
import io.github.cdimascio.dotenv.Dotenv;
import com.hedera.hashgraph.sdk.HederaPreCheckStatusException;
import com.hedera.hashgraph.sdk.HederaReceiptStatusException;
import com.hedera.hashgraph.sdk.TransactionResponse;
import com.hedera.hashgraph.sdk.TransferTransaction;
import com.hedera.hashgraph.sdk.PublicKey;
import com.hedera.hashgraph.sdk.AccountCreateTransaction;
import com.hedera.hashgraph.sdk.Hbar;
import com.hedera.hashgraph.sdk.AccountBalanceQuery;
import com.hedera.hashgraph.sdk.AccountBalance;
import java.util.concurrent.TimeoutException;
Note: You may install the latest version of the Java SDK here.
Step 3: Create your .env File
Create the .env
file in your project's root directory. The .env
file stores your environment variables, such as your account ID and private key.
📣 Note: If you have not created an account, please do so here before this step.
If you created your testnet account through the developer portal, grab the Hedera Testnet account ID and DER-encoded private key from your Hedera portal profile (see screenshot below) and assign them to the MY_ACCOUNT_ID
and MY_PRIVATE_KEY
environment variables in your .env
file:

MY_ACCOUNT_ID=0.0.1234
MY_PRIVATE_KEY=302e020100300506032b657004220420ed5a93073.....
Next, you will load your account ID and private key variables from the .env
file created in the previous step.
Within the main
method, add your testnet account ID and private key from the environment file.
public class HederaExamples {
public static void main(String[] args) {
//Grab your Hedera Testnet account ID and private key
AccountId myAccountId = AccountId.fromString(Dotenv.load().get("MY_ACCOUNT_ID"));
PrivateKey myPrivateKey = PrivateKey.fromString(Dotenv.load().get("MY_PRIVATE_KEY"));
}
}
Step 4: Create your Hedera Testnet client
Create a Hedera Testnet client and set the operator information using the testnet account ID and private key for transaction and query fee authorization. The operator is the default account that will pay for the transaction and query fees in HBAR. You will need to sign the transaction or query with the private key of that account to authorize the payment. In this case, the operator ID is your testnet account ID**.**
and the operator private key is the corresponding testnet account private key.
To avoid encountering the INSUFFICIENT_TX_FEE
error while conducting transactions, you can adjust the maximum transaction fee limit through the .setDefaultMaxTransactionFee()
method. Similarly, the maximum query payment can be adjusted using the .setDefaultMaxQueryPayment()
method.
//Create your Hedera Testnet client
Client client = Client.forTestnet();
//Set your account as the client's operator
client.setOperator(myAccountId, myPrivateKey);
//Set the default maximum transaction fee (in Hbar)
client.setDefaultMaxTransactionFee(new Hbar(100));
//Set the maximum payment for queries (in Hbar)
client.setMaxQueryPayment(new Hbar(50));
Your project environment is now set up to submit transactions and queries to the Hedera test network successfully!
Next, you will learn how to create an account.
Code Check ✅
Contributors: fabianstraubinger99
Last updated
Was this helpful?