Skip to content

[Good First Issue]: Refactor examples/tokens/custom_royalty_fee.py for modularityΒ #1169

@Adityarya11

Description

@Adityarya11

πŸ†•πŸ₯ First Timers Only

This issue is reserved for people who have never contributed or have made minimal contributions to Hiero Python SDK.
We know that creating a pull request (PR) is a major barrier for new contributors.
The goal of this issue and all other issues in find a good first issue is to help you make your first contribution to the Hiero Python SDK.


πŸ‘Ύ Description of the issue

The example script examples/tokens/custom_royalty_fee.py demonstrates how to create a token with royalty fees. However, currently, the code performs all actions (client setup, fee definition, token creation, and verification) inside a single function.

This monolithic structure makes it difficult for new users to understand the distinct steps required to implement royalty fees.

To improve readability and maintain consistency with other examples (like examples/tokens/custom_fractional_fee.py), this script should be refactored into smaller, modular functions.


πŸ’‘ Proposed Solution

The solution is to break the single execution function into distinct helper functions, orchestrated by a main() function.

The logic should be separated into:

  1. Setup: initializing the client.
  2. Construction: creating the fee objects.
  3. Execution: creating the token on the network.
  4. Verification: querying the network to confirm the fee exists.

πŸ‘©β€πŸ’» Implementation Steps

To refactor the example, you need to:

  • Open examples/tokens/custom_royalty_fee.py
  • Extract the client setup logic into setup_client()
  • Extract the fee object creation into create_royalty_fee_object(...)
  • Extract the token creation transaction into create_token_with_fee(...)
  • Extract the verification query into verify_token_fee(...)
  • Create a main() function that calls these steps in order using a context manager (with client:)
  • Ensure the script still runs successfully using uv run examples/tokens/custom_royalty_fee.py

Proposed Solution:

def setup_client():
    """Initialize and set up the client with operator account."""
    # ... logic to return client, operator_id, operator_key

def create_royalty_fee_object(operator_id):
    """Creates the CustomRoyaltyFee object with a fallback fee."""
    # ... logic to return royalty_fee

def create_token_with_fee(client, operator_id, operator_key, royalty_fee):
    """Creates a token with the specified royalty fee attached."""
    # ... logic to return token_id

def verify_token_fee(client, token_id):
    """Queries the network to verify the fee exists."""
    # ... logic to print fee details

def main():
    """Main execution flow."""
    client, operator_id, operator_key = setup_client()

    with client:
        try:
            royalty_fee = create_royalty_fee_object(operator_id)
            token_id = create_token_with_fee(client, operator_id, operator_key, royalty_fee)
            verify_token_fee(client, token_id)
        except Exception as e:
            print(f"Execution failed: {e}")

βœ… Acceptance Criteria

To be able to merge a pull request for this issue, we need:

  • Changelog Entry: Correct changelog entry (please link to the documentation - see guide)
  • Signed commits: commits must be DCO and GPG key signed (see guide)
  • Issue is Solved: The implementation fully addresses the issue requirements as described above

πŸ“‹ Step-by-Step Contribution Guide

If you have never contributed to an open source project at GitHub, the following step-by-step guide will introduce you to the workflow.

  • Claim this issue: Comment below that you are interested in working on the issue. Without assignment, your pull requests might be closed and the issue given to another developer.
  • Wait for assignment: A community member with the given rights will add you as an assignee of the issue
  • 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: 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 attributes:

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!

Happy Coding✌️

Metadata

Metadata

Assignees

Labels

Good First IssueIssues which are ideal for a first time or new project contributor.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions