Skip to content

feat(examples): align example set with Java SDK - #1704

Merged
Dosik13 merged 22 commits into
hiero-ledger:mainfrom
ivostoynovski:feat/align-examples-with-java
May 20, 2026
Merged

feat(examples): align example set with Java SDK#1704
Dosik13 merged 22 commits into
hiero-ledger:mainfrom
ivostoynovski:feat/align-examples-with-java

Conversation

@ivostoynovski

@ivostoynovski ivostoynovski commented May 12, 2026

Copy link
Copy Markdown
Contributor

Description

Aligns the Go SDK examples folder with the Java SDK reference so the example set stays structurally consistent across SDKs. Brings 14 existing examples into parity with their Java counterparts (same flow, step labels, signing patterns). Each example is in its own commit for review.

Aligned examples (mirroring Java):

  • generate-key
  • generate-key-with-mnemonic
  • construct-client
  • create-file
  • transfer-crypto
  • update-account-public-key
  • consensus-pub-sub-with-submit-key
  • topic-with-admin-key
  • multi-app-transfer
  • schedule-multi-sig-transaction
  • consensus-pub-sub-chunked — currently fails when run; tracked in Bug: examples/consensus_pub_sub_chunked fails with "Large topic message was not received!" #1703. Excluded from the run-examples task so CI is unaffected.
  • scheduled-transfer
  • schedule-identical-transaction

Aligned with JS (Java has no equivalent):

  • delete-file

Related

Notes for reviewer

No changes to the SDK itself — examples and the run-examples task only.

Checklist

  • Documented (code comments)
  • Tested

@lfdt-bot

lfdt-bot commented May 12, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codacy-production

codacy-production Bot commented May 12, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 41 complexity · -22 duplication

Metric Results
Complexity 41
Duplication -22

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@ivostoynovski
ivostoynovski force-pushed the feat/align-examples-with-java branch 4 times, most recently from 15b6751 to 7a8eb1f Compare May 12, 2026 10:39
@ivostoynovski
ivostoynovski marked this pull request as ready for review May 12, 2026 10:45
@ivostoynovski
ivostoynovski requested review from a team as code owners May 12, 2026 10:45

@Dosik13 Dosik13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks okay, maybe I will suggest leaving some of the comments that might be useful for new users and also leave the transaction memos as they are useful

Comment thread examples/update_account_public_key/main.go
Comment thread examples/update_account_public_key/main.go
Comment thread examples/update_account_public_key/main.go
ivostoynovski added a commit to ivostoynovski/hiero-sdk-go that referenced this pull request May 12, 2026
…nt-public-key

Per PR hiero-ledger#1704 inline review feedback from @Dosik13: keep narrative comments that help new readers, and keep the SetTransactionMemo call (useful for debugging in mirror node explorers). Re-adds: 3-line comment on the account-key chain, the SetTransactionMemo, a one-line comment on SetKey, and a one-line comment before the two Sign() calls.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dosik13 Dosik13 moved this from 📋 Backlog to 👀 In Review in Hiero SDK Sprint Board May 13, 2026
Comment thread examples/construct_client/main.go Outdated
Comment thread examples/delete_file/main.go
Comment thread examples/consensus_pub_sub_with_submit_key/main.go
Comment thread examples/topic_with_admin_key/main.go
Comment thread examples/consensus_pub_sub_chunked/main.go
Replaces the previous plain-ED25519 demo with an ECDSA
secp256k1 keypair generation + EVM address derivation,
matching GenerateKeyExample.java in the Java SDK and
generate-key.js in the JS SDK.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Reformats the example to use the verbose step-labeled log
style from GenerateKeyWithMnemonicExample.java while keeping
the legacy 22-word phrase block as a Go-specific bonus.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Two changes to match ConstructClientExample.java:
- Hardcode HEDERA_NETWORK to "testnet" instead of reading
  from the environment.
- Set the operator only on testnetClient instead of on all
  four clients.

Other construction patterns (forName, forNetwork, fromConfigFile)
and the SetLedgerID call on the custom client are preserved.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Adds a cleanup-delete at the end of the example to match Java's
CreateFileExample, which creates and then deletes the file. Leaves
no orphaned files on testnet after running.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Adds before/after balance queries, switches GetReceipt to GetRecord so
the memo can be read back, updates the memo string and log lines to
match TransferCryptoExample.java.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Sets a default max transaction fee, switches initial balance from zero
to 1 hbar, drops the custom transaction ID and memo, switches to
PrivateKeyGenerateEd25519, adds a cleanup-delete that returns funds to
the operator, and updates log lines to match Java.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Adds an admin key on the topic, switches the topic memo to the Java
string, switches GeneratePrivateKey to PrivateKeyGenerateEd25519,
publishes 5 messages instead of 3, blocks via a counter+channel up to
60s for all messages to arrive (matches Java's CountDownLatch), adds a
cleanup-delete and client.Close, and switches log lines to Java's
step-labeled style.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Switches the update memo to Java's exact string, switches
GeneratePrivateKey to PrivateKeyGenerateEd25519, adds a cleanup-delete
signed with 3 of the new 4 admin keys, adds client.Close, and updates
log lines to Java's step-labeled style.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Restructures the example to mirror MultiAppTransferExample: creates
an exchange account with SetReceiverSignatureRequired and a user
account with a starting balance, queries balances before and after,
demonstrates two-party signing via a TransactionFromBytes / Sign /
ToBytes round-trip in a separate exchangeSigningService function,
and cleans up by deleting both accounts.

Adds two log lines around the byte round-trip to make the
serialization boundary visible in the output.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Restructures the example to mirror ScheduleMultiSigTransactionExample:

- Initial balance 10 hbar -> 2 hbar
- Adds SetPayerAccountID and SetAdminKey on the scheduled transaction
- Pre-signs the schedule with only privateKey2 (not unsigned)
- ScheduleSignTransaction now signs with only privateKey3, not all
  three keys (the schedule's pedagogical point is progressive multi-
  party signing — only 2 of 3 ever sign, so the schedule remains
  pending and the inner transfer never executes)
- Adds a ScheduleInfoQuery between the create and the second sign
  for inspecting signatory state
- Adds a cleanup AccountDeleteTransaction signed with all 3 keys
- Switches GeneratePrivateKey to PrivateKeyGenerateEd25519
- Drops the SetNodeAccountIDs pinning per cross-SDK alignment
- Switches to Java-style step-labeled log lines

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
TopicMessageQuery subscriptions are flaky under CI. Add consensus_pub_sub and consensus_pub_sub_with_submit_key to the run-examples skip list (consensus_pub_sub_chunked was already excluded). Also switch from a long || chain to a case statement for readability.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Brings the chunked-message example into structural parity with the Java reference (operator-sign, bytes round-trip, submit-key sign, mirror subscription). Also adds the large_message.txt fixture used by the example via go:embed.

The example currently fails with "Large topic message was not received!" against testnet; the failure is tracked separately in hiero-ledger#1703. The example is already on the run-examples task's skip list, so CI is unaffected.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Java has no equivalent example for FileDeleteTransaction; align with the JS port (hiero-ledger/hiero-sdk-js#4047) instead. Adds top-of-file docblock, step-labeled logging, ECDSA key generation, and explicit client.Close().

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Mirror of ScheduledTransferExample.java: separate ScheduleCreate (by Alice) from ScheduleSign (by Bob) so the balance-unchanged-while-pending assertion holds. Adds top-of-file docblock, step-labeled logging, ECDSA key for Bob, before/after ScheduleInfoQuery with TransferTransaction type-check, post-sign balance query, and client.Close().

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Mirror of ScheduleIdenticalTransactionExample.java. Adds top-of-file docblock, step-labeled logging, ECDSA key generation, status enum check (replacing error-string match), full account cleanup, and client.Close() for operator + 3 sub-clients. Uses bare TransactionReceiptQuery.Execute() to read IDENTICAL_SCHEDULE_ALREADY_CREATED receipts without erroring.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
…unt-public-key

Client.SetDefaultMaxTransactionFee returns an error; ignoring it tripped errcheck under golangci-lint.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
…complexity

Extract appendScheduleSignature and deleteAccountWithKeys helpers to drop main's cyclomatic complexity from 34 to ~24, under the gocyclo threshold of 30. No behavior change.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
…nt-public-key

Per PR hiero-ledger#1704 inline review feedback from @Dosik13: keep narrative comments that help new readers, and keep the SetTransactionMemo call (useful for debugging in mirror node explorers). Re-adds: 3-line comment on the account-key chain, the SetTransactionMemo, a one-line comment on SetKey, and a one-line comment before the two Sign() calls.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Replace PrivateKeyGenerateEd25519 with PrivateKeyGenerateEcdsa across the aligned examples, switch the mnemonic example's derivation to ToStandardECDSAsecp256k1PrivateKey, drop the legacy 22-word mnemonic section, and remove the leftover Ed25519 reference from the generate_key docblock. Matches the same migration done in hiero-ledger/hiero-sdk-js#4047.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Per @Dosik13's review on PR hiero-ledger#1704:

- construct_client: read HEDERA_NETWORK from env (peer examples already
  use os.Getenv; drop the introduced const to keep the convention)
- delete_file: add the "Example Start!" / "Example Complete!" banner
  used by sibling examples
- consensus_pub_sub_with_submit_key: SetTransactionMemo on topic create
- topic_with_admin_key: SetTransactionMemo on topic create
- consensus_pub_sub_chunked: SetTransactionMemo on topic create

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
@ivostoynovski
ivostoynovski force-pushed the feat/align-examples-with-java branch from 7a00150 to 90052fc Compare May 20, 2026 06:52
Revert the Taskfile.yml changes introduced in this PR — the skip-list
and run-guard refactoring is out of scope for the examples alignment.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>
Comment thread examples/schedule_multisig_transaction/main.go Outdated
Comment thread examples/schedule_multisig_transaction/main.go Outdated
… prints

Per @Dosik13's review: the transaction transfers HBAR, not tokens.

Signed-off-by: ivo <ivo.stoynovski@limechain.tech>

@Dosik13 Dosik13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@Dosik13
Dosik13 merged commit 5574862 into hiero-ledger:main May 20, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from 👀 In Review to ✅ Done in Hiero SDK Sprint Board May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants