diff --git a/README.md b/README.md index cba4fc152..3edd6cb15 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Hedera™ Hashgraph Java SDK ![](https://img.shields.io/badge/java-17%2B-blue?style=flat-square) -![](https://img.shields.io/badge/android-24%2B-blue?style=flat-square) +![](https://img.shields.io/badge/android-26%2B-blue?style=flat-square) [![](https://img.shields.io/github/actions/workflow/status/hashgraph/hedera-sdk-java/build.yml?style=flat-square)](https://github.com/hashgraph/hedera-sdk-java/actions) [![](https://img.shields.io/maven-central/v/com.hedera.hashgraph/sdk/2?label=maven&style=flat-square)](https://search.maven.org/artifact/com.hedera.hashgraph/sdk) @@ -10,176 +10,40 @@ > fair and secure transactions. Hedera enables and empowers developers to > build an entirely new class of decentralized applications. -## Install +**NOTE**: v1 of the SDK is deprecated and support was discontinued after October 2021. +Please install the latest version 2.x.x or migrate from v1 to the latest 2.x.x version. +You can reference the [migration documentation](docs/sdk/MIGRATING_V1.md). -**NOTE**: v1 of the SDK is deprecated and support will be discontinued after October 2021. Please install the latest version 2.0.x or migrate from v1 to the latest 2.0.x version. You can reference the [migration documentation](/MIGRATING_V1.md). +## Java app quickstart +[The Java application quickstart guide](docs/java-app/java-app-quickstart.md) covers how to properly set up the dependencies +needed to start developing your Java project using the Hedera™ Java SDK. -#### Gradle +## Android app quickstart +[The Android application quickstart guide](docs/android-app/android-app-quickstart.md) covers how to properly set up the dependencies +needed to start developing your Android project using the Hedera™ Java SDK. -Select _one_ of the following depending on your target platform. +## Examples +This repository includes [Java examples](examples/README.md) and [an Android example](example-android/README.md) +that showcase different use cases and workflows. -```groovy -implementation 'com.hedera.hashgraph:sdk:2.31.0' -``` +## Developer quickstart +The [developer quickstart guide](docs/sdk/developer-guide.md) provides instructions on how to set up the environment, +run unit and integration tests, and configure the project to work with different networks +such as the Hedera test network, preview network, etc. -Select _one_ of the following to provide the gRPC implementation. +## Support +If you have a question on how to use the product, please see our +[support guide](https://github.com/hashgraph/.github/blob/main/SUPPORT.md). -```groovy -// netty transport (for high throughput applications) -implementation 'io.grpc:grpc-netty-shaded:1.46.0' - -// netty transport, unshaded (if you have a matching Netty dependency already) -implementation 'io.grpc:grpc-netty:1.46.0' - -// okhttp transport (for lighter-weight applications or Android) -implementation 'io.grpc:grpc-okhttp:1.46.0' -``` - -Select _one_ of the following to enable or disable Simple Logging Facade for Java (SLFJ4). - -```groovy -// Enable logs -implementation 'org.slf4j:slf4j-simple:2.0.3' - -// Disable logs -implementation 'org.slf4j:slf4j-nop:2.0.3' - -``` - - - -#### Maven - -Select _one_ of the following depending on your target platform. - -```xml - - com.hedera.hashgraph - sdk - 2.31.0 - -``` - -Select _one_ of the following to provide the gRPC implementation. - -```xml - - - io.grpc - grpc-netty-shaded - 1.46.0 - - - - - io.grpc - grpc-netty - 1.46.0 - - - - - io.grpc - grpc-okhttp - 1.46.0 - -``` - -## Usage - -Examples of several potential use cases and workflows are available -within the repository in [`examples/`](./examples/src/main/java). - - * [Create Account](./examples/src/main/java/CreateAccountExample.java) - - * [Transfer Hbar](./examples/src/main/java/TransferCryptoExample.java) - - * [Hedera Consensus Service (HCS)](./examples/src/main/java/ConsensusPubSubExample.java) - -## Development - -### Dependencies - - * [Java Development Kit (JDK)](https://adoptopenjdk.net/) v17+ (note this is to _build_, not run) - -### Compile - -```sh -$ ./gradlew compileJava -``` - -### Unit Test - -```sh -$ ./gradlew test -``` - -### Integration Test - -The easiest way to run integration tests is by providing network and operator information in a configuration file. -This configuration file is passed into system properties. - -```sh -$ ./gradlew integrationTest -PCONFIG_FILE="" -``` - -An example configuration file can be found in the repo here: - -[sdk/src/test/resources/client-config-with-operator.json](sdk/src/test/resources/client-config-with-operator.json) - -The format of the configuration file should be as follows: - -``` -{ - "network": { - "": "", - ... - }, - "operator": { - "accountId": "", - "privateKey": "" - } -} -``` - -If a configuration file is not provided, `OPERATOR_ID` and `OPERATOR_KEY` must be passed into system properties -and integration tests will run against the Hedera test network. - -```sh -$ ./gradlew integrationTest -POPERATOR_ID="" -POPERATOR_KEY="" -``` - -`HEDERA_NETWORK` can optionally be used to use `previewnet`. This System Property can only be set to `previewnet`. - -```sh -$ ./gradlew integrationTest -POPERATOR_ID="" -POPERATOR_KEY="" -PHEDERA_NETWORK="previewnet" -``` - -Note: It is also possible to use a custom network in a configuration file and pass `OPERATOR_ID` and `OPERATOR_KEY` -into system properties. - -An example configuration file containing only network information can be found in the repo here: - -[sdk/src/test/resources/client-config.json](sdk/src/test/resources/client-config.json) - -### Examples - -Requires `OPERATOR_ID` and `OPERATOR_KEY` to be in a .env file in the examples directory. Many examples run against -the Hedera test network. - -```sh -$ ./gradlew -q example:run -$ ./gradlew -q example:runGenerateKey -``` - -## Contributing to this Project - -We welcome participation from all developers! +## Contributing +We welcome participation from all developers!\ For instructions on how to contribute to this repo, please -review the [Contributing Guide](CONTRIBUTING.md). +review the [Contributing Guide](docs/sdk/CONTRIBUTING.md).\ +More instructions for contribution can be found in the [Global Contributing Guide](https://github.com/hashgraph/.github/blob/main/CONTRIBUTING.md). -## License Information +## Code of Conduct +This project is governed by the [Contributor Covenant Code of Conduct](https://github.com/hashgraph/.github/blob/main/CODE_OF_CONDUCT.md). By participating, you are +expected to uphold this code of conduct. -Licensed under Apache License, -Version 2.0 – see [LICENSE](LICENSE) in this repo -or [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0). +## License +[Apache License 2.0](LICENSE) diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index 526d6906c..000000000 --- a/RELEASE.md +++ /dev/null @@ -1,33 +0,0 @@ -## Release process of Java SDK - -### Setup - -- Create an account in [sonatype](https://issues.sonatype.org/secure/Signup!default.jspa) -- Someone has to create a JIRA ticket to add your account to the "com.hedera" group ([example](https://issues.sonatype.org/browse/OSSRH-85535)) -- Add these properties in your global `gradle.properties` file (`~/.gradle/gradle.properties`): - - `sonatypeUsername=` - - `sonatypePassword=` - - `signing.keyId=` - - `signing.secretKeyRingFile=/Users//.gnupg/secring.gpg` - -### Releasing - -- Make sure you don’t have any uncommitted changes (The publish task will remove them) -- **Run** the [local node](https://github.com/hashgraph/hedera-local-node) -- Run `task test:integration` -- **Stop** the local node -- Run `task test:unit` -- Create a new branch: `release/vX.Y.Z` -- Change the version in `version.gradle` -- Change the version in `CHANGELOG.md` (from unreleased) -- Change the version in `example-android/app/build.gradle` -- Change the version in README.md (Once in the Gradle section and once in the Maven section) -- Push the changes -- run `task publish` -- Create a PR to merge release/vX.Y.Z to develop -- Finally, merge develop to main -- Go to the [SDK PAGE](https://github.com/hashgraph/hedera-sdk-js/releases) and press the “Draft a new release” button -- Create a new tag from the branch that you are releasing (release/vX.Y.Z) with the same version of the branch -- Copy the latest changes from CHANGELOG.md to the description of the release -- Publish Release diff --git a/docs/android-app/android-app-quickstart.md b/docs/android-app/android-app-quickstart.md new file mode 100644 index 000000000..84ca82749 --- /dev/null +++ b/docs/android-app/android-app-quickstart.md @@ -0,0 +1,22 @@ +## Get started + +> Please note that the minimal Android SDK level required for using the Hedera SDK in an Android project is **26**. + +To get started with an Android project, you'll need to add the following **two** dependencies: + +1. **Hedera™ Java SDK:** +```groovy +implementation 'com.hedera.hashgraph:sdk:2.29.0' +``` + +2. **gRPC implementation:** +```groovy +// okhttp transport (for lighter-weight applications or Android) +implementation 'io.grpc:grpc-okhttp:1.58.0' +``` + +## Next steps +To make it easier to start your Android project using the Hedera™ Java SDK, +we recommend checking out the [Android example](../../example-android/README.md). +This examples show different uses and workflows, +giving you valuable insights into how you can use the Hedera platform in your Android projects. diff --git a/docs/assets/intellij-integration-tests.png b/docs/assets/intellij-integration-tests.png new file mode 100644 index 000000000..268ba2b40 Binary files /dev/null and b/docs/assets/intellij-integration-tests.png differ diff --git a/docs/java-app/create-jar-guide.md b/docs/java-app/create-jar-guide.md new file mode 100644 index 000000000..274407b78 --- /dev/null +++ b/docs/java-app/create-jar-guide.md @@ -0,0 +1,28 @@ +### Creating a fat/uber JAR + +To create a fat/uber jar of your Java application that uses the Hedera™ Java SDK, you need to use the Shadow Gradle plugin: + +```groovy +id "com.github.johnrengelman.shadow" +``` + +and configure it as shown below: +```groovy +tasks.withType().configureEach { + group = "shadow" + from(sourceSets.main.get().output) + mergeServiceFiles() + + // Defer the resolution of 'runtimeClasspath'. This is an issue in the shadow + // plugin that it automatically accesses the files in 'runtimeClasspath' while + // Gradle is building the task graph. The three lines below work around that. + inputs.files(project.configurations.runtimeClasspath) + configurations = emptyList() + doFirst { configurations = listOf(project.configurations.runtimeClasspath.get()) } + + archiveBaseName.set("archive") // Replace with your preferred name + manifest { + attributes["Main-Class"] = "org.example.Main" // Replace with your main class + } +} +``` diff --git a/docs/java-app/java-app-quickstart.md b/docs/java-app/java-app-quickstart.md new file mode 100644 index 000000000..3391c51fa --- /dev/null +++ b/docs/java-app/java-app-quickstart.md @@ -0,0 +1,106 @@ +## Get started + +> Please note that JDK 17 is required. The Temurin builds of [Eclipse Adoptium](https://adoptium.net/) are strongly recommended. + +To get started with a Java project, you'll need to add the following **three** dependencies: + +**1. Hedera Java™ SDK:** + +_Gradle:_ +```groovy +implementation 'com.hedera.hashgraph:sdk:2.31.0' +``` + +_Maven:_ +```xml + + com.hedera.hashgraph + sdk + 2.31.0 + +``` + +**2. gRPC implementation** _(select one of the following)_**:** + +_Gradle:_ +```groovy +// netty transport (for high throughput applications) +implementation 'io.grpc:grpc-netty-shaded:1.57.2' +``` +```groovy +// netty transport, unshaded (if you have a matching Netty dependency already) +implementation 'io.grpc:grpc-netty:1.57.2' +``` +```groovy +// okhttp transport (for lighter-weight applications or Android) +implementation 'io.grpc:grpc-okhttp:1.57.2' +``` + +_Maven:_ +```xml + + + io.grpc + grpc-netty-shaded + 1.57.2 + +``` +```xml + + + io.grpc + grpc-netty + 1.57.2 + +``` +```xml + + + io.grpc + grpc-okhttp + 1.57.2 + +``` + +**3. Simple Logging Facade for Java** _(select one of the following to enable or disable logs)_**:** + +_Gradle:_ +```groovy +// Enable logs +implementation 'org.slf4j:slf4j-simple:2.0.9' +``` +```groovy +// Disable logs +implementation 'org.slf4j:slf4j-nop:2.0.9' +``` + +_Maven:_ +```xml + + + org.slf4j + slf4j-simple + 2.0.9 + +``` +```xml + + + org.slf4j + slf4j-nop + 2.0.9 + +``` + +## Additional useful information +### Fat/uber JAR +[Creating a fat/uber JAR guide](create-jar-guide.md) covers how to properly set up Shadow Gradle plugin +to create a fat/uber JAR of your Java application that uses the Hedera™ Java SDK. + +## Next steps +To make it easier to start your Java project using the Hedera™ Java SDK, +we recommend checking out the [Java examples](../../examples/README.md). +These examples show different uses and workflows, +giving you valuable insights into how you can use the Hedera platform in your projects. +They will also help you explore the capabilities of the Hedera™ Java SDK +and start your project confidently. diff --git a/CONTRIBUTING.md b/docs/sdk/CONTRIBUTING.md similarity index 99% rename from CONTRIBUTING.md rename to docs/sdk/CONTRIBUTING.md index c189e4111..256f90495 100644 --- a/CONTRIBUTING.md +++ b/docs/sdk/CONTRIBUTING.md @@ -78,7 +78,6 @@ Before submitting your pull request, refer to the pull request readiness checkli * [ ] Includes tests to exercise the new behaviour * [ ] Code is documented, especially public and user-facing constructs -* [ ] Local run of `mvn checkstyle:check` succeeds * [ ] Git commit message is detailed and includes context behind the change * [ ] If the change is related to an existing Bug Report or Feature Request, please include its issue number diff --git a/MIGRATING_V1.md b/docs/sdk/MIGRATING_V1.md similarity index 100% rename from MIGRATING_V1.md rename to docs/sdk/MIGRATING_V1.md diff --git a/SDK_ANATOMY.md b/docs/sdk/SDK_ANATOMY.md similarity index 99% rename from SDK_ANATOMY.md rename to docs/sdk/SDK_ANATOMY.md index e74354d78..5ddab1363 100644 --- a/SDK_ANATOMY.md +++ b/docs/sdk/SDK_ANATOMY.md @@ -1,3 +1,5 @@ +> Please note that this document may be a bit outdated. + ## Tools and Libraries: Gradle plugins are used for including libraries and tools. diff --git a/docs/sdk/developer-guide.md b/docs/sdk/developer-guide.md new file mode 100644 index 000000000..8e3fc96fc --- /dev/null +++ b/docs/sdk/developer-guide.md @@ -0,0 +1,129 @@ +## JVM +JDK 17 is required. The Temurin builds of [Eclipse Adoptium](https://adoptium.net/) are strongly recommended. + +## Setup +> Note that the below `./gradlew` commands should be run from the root of the project. + +### Building + +```sh +./gradlew compileJava +``` + +### Unit Tests + +```sh +./gradlew test +``` + +### Integration Tests + +> The tests are only executed if the configuration is provided +> as an environment variable (see the `onlyIf` block in [`sdk/build.gradle`](../../sdk/build.gradle)). +> That's why we need to pass the configuration file at the beginning of the command. +> **The `CONFIG_FILE` environment variable is not used, so you can provide any value, +> but it should not be `null`.** + +#### Using system properties +`OPERATOR_ID`, `OPERATOR_KEY` and `HEDERA_NETWORK` must be passed into system properties.\ +`HEDERA_NETWORK` can be set to `localhost`, `testnet` or `previewnet`. + +```sh +CONFIG_FILE=whatever ./gradlew integrationTest -POPERATOR_ID="" -POPERATOR_KEY="" -PHEDERA_NETWORK="" +``` + +#### Using configuration file + +```sh +CONFIG_FILE=whatever ./gradlew integrationTest -PCONFIG_FILE="" +``` + +An example configuration file can be found in the repo here: +[sdk/src/test/resources/client-config-with-operator.json](../../sdk/src/test/resources/client-config-with-operator.json) + +**Running against the local network** + +The format of the configuration file should be as follows: +```json +{ + "network": { + "0.0.3": "127.0.0.1:50211" + }, + "mirrorNetwork": [ + "127.0.0.1:5600" + ], + "operator": { + "accountId": "0.0.1022", + "privateKey": "0xa608e2130a0a3cb34f86e757303c862bee353d9ab77ba4387ec084f881d420d4" + } +} + +``` + +**Running against remote networks** + +The format of the configuration file should be as follows: +```json +{ + "network": "testnet", + "operator": { + "accountId": "0.0.7", + "privateKey": "d5d37..." + } +} +``` + +`HEDERA_NETWORK` can be set to `testnet`, `previewnet` or `mainnet`. + +#### Running individual test classes or functions + +Running test class: +```sh +CONFIG_FILE=whatever ./gradlew integrationTest -POPERATOR_ID="" -POPERATOR_KEY="" -PHEDERA_NETWORK="testnet" --tests "" +``` + +Running test function: +```sh +CONFIG_FILE=whatever ./gradlew integrationTest -POPERATOR_ID="" -POPERATOR_KEY="" -PHEDERA_NETWORK="testnet" --tests "" +``` + +#### Running with Intellij IDEA +1. Create a new Gradle run configuration (easiest way is to run test class or individual test function from the IDE). +2. Update "Run" configuration to pass the required system properties (`OPERATOR_ID`, `OPERATOR_KEY` and `HEDERA_NETWORK`). +3. Update "Environment variables" to pass the `CONFIG_FILE=whatever`. + + +## Maintaining generated files +>To execute the tasks below, you need to install the tool from this link: https://taskfile.dev/ +> (these tasks are from the file Taskfile.yml, which is located in the root of the repository). +> Once installed, you can run the commands as shown below. +> +> Note that the below `task` commands should be run from the root of the project. + +### Updating unit tests snapshots +```sh +task update:snapshots +``` + +### Updating proto files +```sh +task update:proto +``` + +### Updating address books +Update all address books: +```sh +task update:addressbooks +``` +Update address books only for a mainnet: +```sh +task update:addressbooks:mainnet +``` +Update address books only for a testnet: +```sh +task update:addressbooks:testnet +``` +Update address books only for a previewnet: +```sh +task update:addressbooks:previewnet +``` diff --git a/example-android/README.md b/example-android/README.md index 377f7c794..fe3969998 100644 --- a/example-android/README.md +++ b/example-android/README.md @@ -1,17 +1,50 @@ -# Example Android app +# Example Android application -Running the example requires `operator_id` and `operator_key` resource strings to be set in `app/src/main/res/values/strings.xml` +## Description +Example Android Application is designed to showcase various functionalities +and capabilities when working with the Hedera™ Java SDK. +It operates on a `testnet` environment and offers the following features +through three distinct tabs: +- **Private Key tab** allows you to generate ED25519 key pairs by pressing +the "Generate" button. +- **Account Balance tab** allows you to retrieve the balance of an account by +pressing the "Get Account Balance" button and specifying the desired account, +which can be different from the default account specified in the + [`app/src/main/res/values/strings.xml`](../example-android/app/src/main/res/values/strings.xml) file. +- **Crypto Transfer tab** allows you to transfer a specified amount of HBARs +from your account to a recipient account by pressing the "Send HBAR" button +and setting the recipient's account in the provided text field. + +## Usage + +### Configuration +Running the example requires `operator_id` and `operator_key` +resource strings to be set in +[`app/src/main/res/values/strings.xml`](../example-android/app/src/main/res/values/strings.xml). ```xml ... ... ``` -## Running with a local SDK version - -By default, the example uses the SDK version published on Maven Central. If you want to use the local version you need to do this: - +### Running with a local SDK version +By default, the example uses the SDK version published on Maven Central. +If you want to use the local version, follow the steps below: - Publish the SDK to the local Maven repo - `./gradlew :sdk:publishToMavenLocal` - Uncomment the `mavenLocal()` line in `example-android/build.gradle` - Build the example - `./gradlew :example-android:build --refresh-dependencies` - Run the example + +> Note that the above `./gradlew` commands should be run from the root of the project. + +> If you get the following error: +> `Cannot perform signing task ':sdk:signMavenJavaPublication' because it has no configured signatory` +> , then you should be able to resolve the error by providing the expected GPG variables in +> the `gradle.properties` file in your `HOME` directory: + +```properties +# File location: ~/.gradle/gradle.properties - see https://docs.gradle.org/current/userguide/directory_layout.html +signing.keyId=248... +signing.password=sec... +signing.secretKeyRingFile=/Users/me/... +``` diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..3f24d1bc5 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,111 @@ +## Java examples + +### SDK +* [Construct a client](../examples/src/main/java/ConstructClientExample.java) +* [Generate a key](../examples/src/main/java/GenerateKeyExample.java) +* [Generate a key (with mnemonic)](../examples/src/main/java/GenerateKeyWithMnemonicExample.java) +* [Get address book](../examples/src/main/java/GetAddressBookExample.java) +* [Get exchange rates](../examples/src/main/java/GetExchangeRatesExample.java) +* [Logger](../examples/src/main/java/LoggerFunctionalitiesExample.java) + +### Transactions +* [Sign a transaction](../examples/src/main/java/SignTransactionExample.java) +* [Transaction serialization](../examples/src/main/java/TransactionSerializationExample.java) + +### Schedule Transaction +* [Sign a scheduled transfer transaction](../examples/src/main/java/ScheduleExample.java) +* [Sign a scheduled transfer transaction (with comments)](../examples/src/main/java/ScheduledTransferExample.java) +* [Schedule identical transaction](../examples/src/main/java/ScheduleIdenticalTransactionExample.java) +* [Schedule multisig transaction](../examples/src/main/java/ScheduleMultiSigTransactionExample.java) +* [Schedule multisig transaction (with threshold)](../examples/src/main/java/ScheduledTransactionMultiSigThresholdExample.java) + +### Accounts and HBAR +* [Create an account](../examples/src/main/java/CreateAccountExample.java) +* [Create an account (threshold key)](../examples/src/main/java/CreateAccountThresholdKeyExample.java) +* [Create an account (with alias)](../examples/src/main/java/CreateAccountWithAliasExample.java) +* [Create an account (with alias and receiver signature required)](../examples/src/main/java/CreateAccountWithAliasAndReceiverSignatureRequiredExample.java) +* [Account creation ways](../examples/src/main/java/AccountCreationWaysExample.java) +* [Create an account with Hts](../examples/src/main/java/AccountCreateWithHtsExample.java) +* [Auto create an account with transfer transaction](../examples/src/main/java/AutoCreateAccountTransferTransactionExample.java) +* [Account alias](../examples/src/main/java/AccountAliasExample.java) +* [Account allowance](../examples/src/main/java/AccountAllowanceExample.java) +* [Get account info](../examples/src/main/java/GetAccountInfoExample.java) +* [Get account balance](../examples/src/main/java/GetAccountBalanceExample.java) +* [Update an account](../examples/src/main/java/UpdateAccountPublicKeyExample.java) +* [Delete an account](../examples/src/main/java/DeleteAccountExample.java) +* [Staking](../examples/src/main/java/StakingExample.java) +* [Staking (with update)](../examples/src/main/java/StakingWithUpdateExample.java) +* [Multisig](../examples/src/main/java/MultiSigOfflineExample.java) + +### Consensus Service +* [Create a topic](../examples/src/main/java/CreateTopicExample.java) +* [Topic management](../examples/src/main/java/TopicWithAdminKeyExample.java) +* [Consensus Pub Sub](../examples/src/main/java/ConsensusPubSubExample.java) +* [Consensus Pub Sub (chunked)](../examples/src/main/java/ConsensusPubSubChunkedExample.java) +* [Consensus Pub Sub (with submit key)](../examples/src/main/java/ConsensusPubSubWithSubmitKeyExample.java) + +### Token Service +* [Transfer Hbar](../examples/src/main/java/TransferCryptoExample.java) +* [Transfer Hbar (multi app)](../examples/src/main/java/MultiAppTransferExample.java) +* [Transfer tokens](../examples/src/main/java/TransferTokensExample.java) +* [Transfer using EVM address](../examples/src/main/java/TransferUsingEvmAddressExample.java) +* [Custom fees](../examples/src/main/java/CustomFeesExample.java) +* [Custom fees (exempt)](../examples/src/main/java/ExemptCustomFeesExample.java) +* [NFT Allowances](../examples/src/main/java/NftAddRemoveAllowancesExample.java) +* [Zero token operations](../examples/src/main/java/ZeroTokenOperationsExample.java) + +### File Service +* [Create a file](../examples/src/main/java/CreateFileExample.java) +* [File append (chunked)](../examples/src/main/java/FileAppendChunkedExample.java) +* [Get file contents](../examples/src/main/java/GetFileContentsExample.java) +* [Delete a file](../examples/src/main/java/DeleteFileExample.java) + +### Smart Contract Service +* [Create a contract](../examples/src/main/java/CreateSimpleContractExample.java) +* [Create a stateful contract](../examples/src/main/java/CreateStatefulContractExample.java) +* [Contract nonce (HIP-729)](../examples/src/main/java/ContractNoncesExample.java) +* [Interaction with a contract](../examples/src/main/java/SolidityPrecompileExample.java) + +### Miscellaneous +* [Checksum validation](../examples/src/main/java/ValidateChecksumExample.java) +* [Pseudorandom Number Generator](../examples/src/main/java/PrngExample.java) + +## Usage + +### Configuration +Running the examples requires `.env` file to exist under [`root project folder`](../): + +```sh +cp .env.sample ../.env +``` + +The `OPERATOR_ID` and `OPERATOR_KEY` variables should be set in a `.env` file. +Optionally, you can set the `HEDERA_NETWORK` variable to `testnet`, `previewnet`, or `mainnet` +for configuring the network. If the `HEDERA_NETWORK` is not set, it will default to `testnet`.\ +Therefore, the format of the configuration file should be as follows: + +```.properties +OPERATOR_ID=0.0.102... +OPERATOR_KEY=0xeae... +# Optionally set HEDERA_NETWORK +HEDERA_NETWORK=previewnet +``` + +### Running with Gradle + +> Note that the below `./gradlew` commands should be run from the root of the project. + +Template: + +```sh +./gradlew -q example:run +``` + +Concrete example: + +```sh +./gradlew -q example:runGenerateKey +``` + +### Running with Intellij +Simply execute the main function of the desired example.