refactor: update example client setup to use Client.from_env()#2093
Conversation
Up to standards ✅🟢 Issues
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughRefactored setup_client across many example scripts to use Client.from_env(), removed manual Network/OPERATOR parsing and try/except exit wrappers, added explicit return type annotations in many helpers, and updated startup logging to print client.network.network and client.operator_account_id. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 18
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
examples/account/account_allowance_delete_transaction_nft.py (1)
44-55:⚠️ Potential issue | 🟠 MajorMake
setup_client()fail gracefully before main flow starts.Because
setup_client()is called before themain()try-block, anyClient.from_env()failure currently exits via traceback. Handle this inside setup and terminate withsys.exit(1).Suggested patch
def setup_client() -> tuple[Client, AccountId, PrivateKey]: """Setup Client.""" - client = Client.from_env() + try: + client = Client.from_env() + except Exception as e: + print(f"Failed to set up client: {e}") + sys.exit(1) operator_id = client.operator_account_id operator_key = client.operator_private_keyAs per coding guidelines, examples should include
try-exceptblocks withsys.exit(1)for critical failures.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 76833f10-638c-4c33-ac8d-5501e69f2c6e
📒 Files selected for processing (42)
CHANGELOG.mdexamples/account/account_allowance_approve_transaction_hbar.pyexamples/account/account_allowance_approve_transaction_nft.pyexamples/account/account_allowance_delete_transaction_hbar.pyexamples/account/account_allowance_delete_transaction_nft.pyexamples/account/account_records_query.pyexamples/client/client.pyexamples/consensus/topic_message_submit_chunked_transaction.pyexamples/consensus/topic_message_submit_transaction.pyexamples/consensus/topic_update_transaction.pyexamples/contract/contract_bytecode_query.pyexamples/contract/contract_call_query.pyexamples/contract/contract_create_transaction_no_constructor_parameters.pyexamples/contract/contract_create_transaction_with_bytecode.pyexamples/contract/contract_create_transaction_with_constructor_parameters.pyexamples/contract/contract_execute_transaction.pyexamples/contract/contract_execute_transaction_with_value.pyexamples/contract/contract_update_transaction.pyexamples/contract/ethereum_transaction.pyexamples/file/file_append_transaction.pyexamples/file/file_contents_query.pyexamples/file/file_delete_transaction.pyexamples/file/file_info_query.pyexamples/file/file_update_transaction.pyexamples/logger/logging_example.pyexamples/prng_transaction.pyexamples/schedule/schedule_create_transaction.pyexamples/schedule/schedule_delete_transaction.pyexamples/schedule/schedule_info_query.pyexamples/schedule/schedule_sign_transaction.pyexamples/tls_query_balance.pyexamples/transaction/batch_transaction.pyexamples/transaction/custom_fee_limit.pyexamples/transaction/transaction_freeze_manually.pyexamples/transaction/transaction_freeze_secondary_client.pyexamples/transaction/transaction_freeze_without_operator.pyexamples/transaction/transaction_to_bytes.pyexamples/transaction/transfer_transaction_fungible.pyexamples/transaction/transfer_transaction_gigabar.pyexamples/transaction/transfer_transaction_hbar.pyexamples/transaction/transfer_transaction_nft.pyexamples/transaction/transfer_transaction_tinybar.py
AntonioCeppellini
left a comment
There was a problem hiding this comment.
HI @ParasSalonia thanks for your contribution! :D
have you tried to run the examples locally? do they works fine with the new client setup?
|
Hi I wanted to clarify a couple of things regarding this issue.
|
|
Hi @ParasSalonia |
|
Hi @ParasSalonia please also rebase and delete your changelog entry, we are not using that anymore |
|
please follow https://github.com/hiero-ledger/sdk-collaboration-hub/blob/main/guides/issue-progression/for-developers/rebasing.md and https://github.com/hiero-ledger/sdk-collaboration-hub/blob/main/guides/issue-progression/for-developers/merge_conflicts.md, when it is ready to review again mark it so. Thanks |
Signed-off-by: ParasSalonia <parassalonia22@gmail.com>
Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Added error handling for client setup to check environment variables. Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
exploreriii
left a comment
There was a problem hiding this comment.
Hi @ParasSalonia please triple check the example run, check all is as expected and note the failed run
https://github.com/hiero-ledger/hiero-sdk-python/actions/runs/25064955743/job/73436923567?pr=2093
Signed-off-by: ParasSalonia <parassalonia22@gmail.com>
63b114c to
4d3676a
Compare
Signed-off-by: ParasSalonia <parassalonia22@gmail.com>
exploreriii
left a comment
There was a problem hiding this comment.
@manishdait what do you think about this?
the client does not specify the network if blank, but network defaults to testnet.
should we make a change later in another PR to be more explicit?
|
Please click update branch @ParasSalonia |
Up to standards ✅🟢 Issues
|
…-ledger#2093) Signed-off-by: ParasSalonia <parassalonia22@gmail.com> Signed-off-by: Paras Salonia <parassalonia22@gmail.com>
Changes
Refactored example files to replace manual client setup with the simplified
Client.from_env()method.Replaced manual client initialization (
Client(network)+set_operator) withClient.from_env()Removed redundant environment variable parsing and operator setup logic
Standardized client setup across example scripts for consistency and readability
Linked issue