-
Notifications
You must be signed in to change notification settings - Fork 152
Description
🐥 Beginner Friendly
This issue is intended for contributors who have previously completed a Good First Issue in Hiero and are at a beginner level.
We recognize that gaining confidence and building skills are equally important steps in the open-source contributor journey.
The purpose of this issue—and others listed under Find a beginner issue—is to provide a supportive, low-pressure environment where you can learn, practice, and grow your contribution skills with confidence.
👾 Description of the issue
At examples/account we have several examples relating to accounts.
Some of these have a set up client function.
For example:
examples/account/account_allowance_approve_transaction_hbar.py
has:
load_dotenv()
network_name = os.getenv("NETWORK", "testnet").lower()
def setup_client() -> Client:
"""Initialize and set up the client with operator account using env vars."""
network = Network(network_name)
print(f"Connecting to Hedera {network_name} network!")
client = Client(network)
operator_id = AccountId.from_string(os.getenv("OPERATOR_ID", ""))
operator_key = PrivateKey.from_string(os.getenv("OPERATOR_KEY", ""))
client.set_operator(operator_id, operator_key)
print(f"Client set up with operator id {client.operator_account_id}")
return clientWe now have a method defined at src/hiero_sdk_python/client/client.py that will enable you to do this a lot quicker
@classmethod
def from_env(cls, network: Optional[NetworkName] = None) -> "Client":
"""
Initialize client from environment variables.
Automatically loads .env file if present.
Args:
network (str, optional): Override the network ("testnet", "mainnet", "previewnet").
If not provided, checks 'NETWORK' env var.
Defaults to 'testnet' if neither is set.
Raises:
ValueError: If OPERATOR_ID or OPERATOR_KEY environment variables are not set.
Example:
# Defaults to testnet if no env vars set
client = Client.from_env()
"""
load_dotenv()
if network:
network_name = network
else:
network_name = os.getenv('NETWORK') or 'testnet'
network_name = network_name.lower()
try:
client = cls(Network(network_name))
except ValueError:
raise ValueError(f"Invalid network name: {network_name}")
operator_id_str = os.getenv("OPERATOR_ID")
operator_key_str = os.getenv("OPERATOR_KEY")
if not operator_id_str:
raise ValueError("OPERATOR_ID environment variable is required for Client.from_env()")
if not operator_key_str:
raise ValueError("OPERATOR_KEY environment variable is required for Client.from_env()")
operator_id = AccountId.from_string(operator_id_str)
operator_key = PrivateKey.from_string(operator_key_str)
client.set_operator(operator_id, operator_key)
return client💡 Proposed Solution
This means we can refactor the old-style set up client function to use this new from_env method, removing many lines of code.
We can do this for all examples/account that set up a client.
👩💻 Implementation Steps
Refactor the old set up client with the new method
Remove unused imports/etc
See examples at:
examples/client/client.py
or:
examples/account/account_create_transaction_without_alias.py
Please complete this for all remaining account examples
✅ Acceptance Criteria
To be able to merge a pull request for this issue, we need:
- Assignment: You must be assigned to the issue, comment:
/assignin the issue to get assigned see guide - Changelog Entry: Correct changelog entry see guide
- Signed commits: commits must be DCO and GPG key signed see guide
- All Tests Pass: our workflow checks like unit and integration tests must pass
- Issue is Solved: The implementation fully addresses the issue requirements as described above
- No Further Changes are Made: Code review feedback has been addressed and no further changes are requested
📋 Step-by-Step Contribution Guide
- Assignment: You must be assigned to the issue, comment:
/assignin the issue to get assigned see guide - Fork, Branch and Work on the issue: Create a copy of the repository, create a branch for the issue and solve the problem. For instructions, please read our Contributing guide file. Further help can be found at Set-up Training and Workflow Training.
- DCO and GPG key sign each commit : each commit must be -s and -S signed. An explanation on how to do this is at Signing Guide
- Add a Changelog Entry : your pull request will require a changelog. Read Changelog Entry Guide to learn how.
- Push and Create a Pull Request : Once your issue is resolved, and your commits are signed, and you have a changelog entry, push your changes and create a pull request. Detailed instructions can be found at Submit PR Training, part of Workflow Training.
- You did it 🎉: A maintainer or committer will review your pull request and provide feedback. If approved, we will merge the fix in the main branch. Thanks for being part of the Hiero community as an open-source contributor ❤️
IMPORTANT You will ONLY be assigned to the issue if you comment: /assign
IMPORTANT Your pull request CANNOT BE MERGED until you add a changelog entry AND sign your commits each with git commit -S -s -m "chore: your commit message" with a GPG key setup.
🤔 Additional Information
For more help, we have extensive documentation:
Additionally, we invite you to join our community on our Discord server.
We also invite you to attend each Wednesday, 2pm UTC our Python SDK Office Hour and Community Calls. The Python SDK Office hour is for hands-on-help and the Community Call for general community discussion.
You can also ask for help in a comment below!