-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into implement-MirrorNodeContractQuery-
- Loading branch information
Showing
26 changed files
with
535 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...main/java/com/hedera/hashgraph/sdk/examples/InitializeClientWithMirrorNetworkExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*- | ||
* | ||
* Hedera Java SDK | ||
* | ||
* Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.hedera.hashgraph.sdk.examples; | ||
|
||
import com.hedera.hashgraph.sdk.AccountCreateTransaction; | ||
import com.hedera.hashgraph.sdk.AccountId; | ||
import com.hedera.hashgraph.sdk.Client; | ||
import com.hedera.hashgraph.sdk.Hbar; | ||
import com.hedera.hashgraph.sdk.PrivateKey; | ||
import com.hedera.hashgraph.sdk.logger.LogLevel; | ||
import com.hedera.hashgraph.sdk.logger.Logger; | ||
import io.github.cdimascio.dotenv.Dotenv; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class InitializeClientWithMirrorNetworkExample { | ||
/* | ||
* See .env.sample in the examples folder root for how to specify values below | ||
* or set environment variables with the same names. | ||
*/ | ||
|
||
/** | ||
* Operator's account ID. Used to sign and pay for operations on Hedera. | ||
*/ | ||
private static final AccountId OPERATOR_ID = AccountId.fromString( | ||
Objects.requireNonNull(Dotenv.load().get("OPERATOR_ID"))); | ||
|
||
/** | ||
* Operator's private key. | ||
*/ | ||
private static final PrivateKey OPERATOR_KEY = PrivateKey.fromString( | ||
Objects.requireNonNull(Dotenv.load().get("OPERATOR_KEY"))); | ||
|
||
/** | ||
* SDK_LOG_LEVEL defaults to SILENT if not specified in dotenv file. Log levels can be: TRACE, DEBUG, INFO, WARN, | ||
* ERROR, SILENT. | ||
* <p> | ||
* Important pre-requisite: set simple logger log level to same level as the SDK_LOG_LEVEL, for example via VM | ||
* options: -Dorg.slf4j.simpleLogger.log.com.hedera.hashgraph=trace | ||
*/ | ||
private static final String SDK_LOG_LEVEL = Dotenv.load().get("SDK_LOG_LEVEL", "SILENT"); | ||
|
||
public static void main(String[] args) throws Exception { | ||
/* | ||
* Step 0: | ||
* Create and configure the SDK Client. | ||
*/ | ||
Client client = Client.forMirrorNetwork(List.of("testnet.mirrornode.hedera.com:443")); | ||
// All generated transactions will be paid by this account and signed by this key. | ||
client.setOperator(OPERATOR_ID, OPERATOR_KEY); | ||
// Attach logger to the SDK Client. | ||
client.setLogger(new Logger(LogLevel.valueOf(SDK_LOG_LEVEL))); | ||
|
||
/* | ||
* Step 1: | ||
* Generate ED25519 key pair. | ||
*/ | ||
System.out.println("Generating ED25519 key pair..."); | ||
PrivateKey privateKey = PrivateKey.generateED25519(); | ||
|
||
/* | ||
* Step 2: | ||
* Create account | ||
*/ | ||
AccountId aliceId = new AccountCreateTransaction() | ||
.setKey(privateKey) | ||
.setInitialBalance(Hbar.from(5)) | ||
.execute(client) | ||
.getReceipt(client) | ||
.accountId; | ||
Objects.requireNonNull(aliceId); | ||
System.out.println("Alice's account ID: " + aliceId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.