Skip to content

Conversation

@Adityarya11
Copy link
Contributor

@Adityarya11 Adityarya11 commented Dec 19, 2025

This pull request updates the examples/tokens/custom_fee_royalty.py example to be a full end-to-end demonstration that interacts with the Hedera network, rather than just showing static object creation. It also updates the changelog to reflect this enhancement.

End-to-end example improvements:

  • Refactored examples/tokens/custom_fee_royalty.py to connect to the Hedera network, create a token with a custom royalty fee, and verify the fee on the network, making it a practical, executable example.

Documentation updates:

  • Updated CHANGELOG.md to note that examples/tokens/custom_fee_royalty.py is now an end-to-end network example.Description:

Related issue(s):

Fixes #1154

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Summary by CodeRabbit

  • Documentation
    • Updated custom royalty fee example with environment variable-based configuration
    • Demonstrates creating non-fungible tokens with custom fixed and royalty fees
    • Shows fee collector setup and verification through token information queries
    • Includes enhanced error handling and network status reporting

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 19, 2025 09:58
@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Warning

Rate limit exceeded

@Adityarya11 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e675db6 and bc0f378.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • examples/tokens/custom_fee_royalty.py (1 hunks)

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR transforms the custom_fee_royalty.py example from a unit-style object demonstration into a functional end-to-end example. It adds environment-based client setup, creates tokens with royalty fees on the Hedera network, and verifies the fees through query operations. A CHANGELOG entry documents the addition.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added unreleased entry documenting the new end-to-end example for custom royalty fees.
Example Transformation
examples/tokens/custom_fee_royalty.py
Complete rewrite from unit-style demo to end-to-end example. Added setup_client() function for environment-based client initialization with dotenv support. Replaced custom_royalty_fee() with custom_royalty_fee_example() that creates a token with custom royalty and fixed fees, executes the transaction, and verifies fees via TokenInfoQuery. Includes error handling and proper client cleanup.

Sequence Diagram

sequenceDiagram
    actor User
    participant Script as custom_fee_royalty.py
    participant Client
    participant Network as Hedera Network
    participant Ledger

    User->>Script: uv run example
    Script->>Script: load_dotenv()
    Script->>Client: setup_client() with OPERATOR_ID/KEY
    Client->>Network: Initialize and validate connection
    Network-->>Client: Connection established

    Script->>Script: Build CustomFixedFee (1 HBAR fallback)
    Script->>Script: Build CustomRoyaltyFee (5%)
    Script->>Script: Create TokenCreateTransaction with fees
    
    Script->>Network: Submit TokenCreateTransaction (sign & execute)
    Network->>Ledger: Create non-fungible token with fees
    Ledger-->>Network: Receipt with token ID
    Network-->>Script: Transaction receipt

    Script->>Script: Check receipt status
    Script->>Network: TokenInfoQuery to verify fees
    Network->>Ledger: Query token information
    Ledger-->>Network: Token details with fees
    Network-->>Script: Fee configuration confirmed
    
    Script->>User: Print token ID and verified fees
    Script->>Client: Close client connection
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • examples/tokens/custom_fee_royalty.py: Complete rewrite involving multiple new operations (client setup, fee construction, token creation, query verification). Requires verification of environment variable handling, transaction flow, fee configuration, and query result interpretation.
  • Integration points: Ensure proper error handling around transaction execution and client resource cleanup in the finally block.
  • Fee setup: Verify that the CustomFixedFee and CustomRoyaltyFee are constructed correctly and that the operator is properly assigned as the fee collector.

Possibly related issues

Suggested reviewers

  • exploreriii

Poem

🐰 A token hops through the Hedera chain,
With royalties flowing in fees, not in vain,
Custom fees configured, verified true—
From script to ledger, an example for you! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: refactoring the custom_fee_royalty.py example to be executable end-to-end.
Linked Issues check ✅ Passed The PR successfully implements all required objectives from issue #1154: client setup with environment variables, custom royalty fee creation, token creation with fees, receipt verification, and TokenInfoQuery for fee validation.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #1154 requirements. The CHANGELOG.md update documents the transformation, and no unrelated modifications were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1155   +/-   ##
=======================================
  Coverage   91.19%   91.19%           
=======================================
  Files         139      139           
  Lines        8447     8447           
=======================================
  Hits         7703     7703           
  Misses        744      744           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
CHANGELOG.md (1)

81-81: Consider adding issue/PR reference for consistency.

Many entries in this changelog include issue or PR references (e.g., (#1154)). Adding the reference would improve traceability.

-- Transformed `examples/tokens/custom_fee_royalty.py` to be an end-to-end example, that interacts with the Hedera network, rather than a static object demo.
+- Transformed `examples/tokens/custom_fee_royalty.py` to be an end-to-end example, that interacts with the Hedera network, rather than a static object demo. (#1154)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d53489c and e675db6.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • examples/tokens/custom_fee_royalty.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.8)
examples/tokens/custom_fee_royalty.py

41-41: Abstract raise to an inner function

(TRY301)


41-41: Avoid specifying long messages outside the exception class

(TRY003)


48-48: Consider moving this statement to an else block

(TRY300)


78-78: f-string without any placeholders

Remove extraneous f prefix

(F541)


79-79: f-string without any placeholders

Remove extraneous f prefix

(F541)


81-81: f-string without any placeholders

Remove extraneous f prefix

(F541)


121-121: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Agent
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: run-examples
  • GitHub Check: build-and-test (3.12)
  • GitHub Check: build-and-test (3.10)
  • GitHub Check: build-and-test (3.13)
  • GitHub Check: build-and-test (3.11)
  • GitHub Check: StepSecurity Harden-Runner
🔇 Additional comments (3)
examples/tokens/custom_fee_royalty.py (3)

7-25: LGTM!

Imports and environment configuration follow the established pattern from other examples in this repository.


82-97: LGTM!

Token creation is correctly configured as a non-fungible token with royalty fees, following the requirements from issue #1154.


99-128: LGTM!

The execution flow with try/except/finally ensures proper cleanup, and the token info query correctly verifies the custom fees. The broad Exception catch (line 121) is acceptable for a demonstration example to capture any network or SDK errors gracefully.

Comment on lines 78 to 81
print(f"Royalty Fee Configured: 5/100 (5%)")
print(f"Fallback Fee: 1 HBAR")

print(f"\n--- Creating TOken with Royalty Fee ---")
Copy link

@coderabbitai coderabbitai bot Dec 19, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove extraneous f prefixes from strings without placeholders.

Lines 78, 79, and 81 use f-strings but contain no placeholders. Also, line 81 has a typo: "TOken" → "Token".

🔎 Proposed fix
-    print(f"Royalty Fee Configured: 5/100 (5%)")
-    print(f"Fallback Fee: 1 HBAR")
+    print("Royalty Fee Configured: 5/100 (5%)")
+    print("Fallback Fee: 1 HBAR")
     
-    print(f"\n--- Creating TOken with Royalty Fee ---")
+    print("\n--- Creating Token with Royalty Fee ---")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print(f"Royalty Fee Configured: 5/100 (5%)")
print(f"Fallback Fee: 1 HBAR")
print(f"\n--- Creating TOken with Royalty Fee ---")
print("Royalty Fee Configured: 5/100 (5%)")
print("Fallback Fee: 1 HBAR")
print("\n--- Creating Token with Royalty Fee ---")
🧰 Tools
🪛 Ruff (0.14.8)

78-78: f-string without any placeholders

Remove extraneous f prefix

(F541)


79-79: f-string without any placeholders

Remove extraneous f prefix

(F541)


81-81: f-string without any placeholders

Remove extraneous f prefix

(F541)

🤖 Prompt for AI Agents
In examples/tokens/custom_fee_royalty.py around lines 78 to 81, the three print
statements use unnecessary f-string prefixes and one contains a typo ("TOken"
should be "Token"); remove the leading f from those string literals (use normal
strings) and correct "TOken" to "Token" so the lines read as plain prints
without f-strings and with the fixed capitalization/word.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a reasonable suggestion.
f strings should only be used if you are adding some variable inside it e.g.
print(f"Fallback Fee: {Amount} HBAR")
otherwise you can just do
print("Fallback Fee: 1 HBAR")

The bigger issue is you should pull these variables in from what you added to the token, then add them to your f string

Copy link

Choose a reason for hiding this comment

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

@exploreriii, you're absolutely right! Pulling the values directly from the fee objects makes the code more robust and maintainable. Here's how the print statements should be refactored to use actual values from the objects:

# Extract values from the fee objects
fallback_amount_hbar = Hbar.from_tinybars(fallback_fee.amount)
royalty_numerator = royalty_fee.numerator
royalty_denominator = royalty_fee.denominator
royalty_percentage = (royalty_numerator / royalty_denominator) * 100

print(f"Royalty Fee Configured: {royalty_numerator}/{royalty_denominator} ({royalty_percentage}%)")
print(f"Fallback Fee: {fallback_amount_hbar} HBAR")

print("\n--- Creating Token with Royalty Fee ---")

This way:

  1. If someone changes numerator=5 to numerator=10, the print will automatically show "10/100 (10%)"
  2. If the fallback fee changes from Hbar(1) to Hbar(2), it will automatically display "2 HBAR"
  3. The f-strings now have a clear purpose - interpolating actual variables

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the examples/tokens/custom_fee_royalty.py example to be a full end-to-end executable demonstration that interacts with the Hedera network, replacing the previous static object creation example. The update aligns this example with similar token examples in the repository.

  • Transforms a static demo into an interactive network example with actual token creation and verification
  • Adds comprehensive setup, execution, and verification workflow
  • Updates CHANGELOG.md to document the enhancement

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
examples/tokens/custom_fee_royalty.py Complete refactor from static object demonstration to end-to-end network example with client setup, token creation with custom royalty fee, and network verification
CHANGELOG.md Documents the transformation of custom_fee_royalty.py to an end-to-end example

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +103 to +102
if receipt.status != ResponseCode.SUCCESS:
print(f"Transaction failed with status: {ResponseCode(receipt.status).name}")
return
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

Missing early return after error status check. When the transaction fails (line 103-105), the function should return early to prevent executing the remaining code. Without this return, the code will continue to line 107 and attempt to access receipt.token_id, which may not be set when the transaction fails, potentially causing an error.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

yes

"""
Run with:
uv run examples/tokens/custom_royalty_fee.py
python examples/tokens/custom_royalty_fee.py
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The filename in the comment is incorrect. It should be 'custom_fee_royalty.py' to match the actual filename, not 'custom_royalty_fee.py'.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

your file name should be custom_royalty_fee.py to match the exact src name
src/hiero_sdk_python/tokens/custom_royalty_fee.py

print(f"Transaction failed: {e}")
sys.exit(1)
finally:
client.close()
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

Instance of context-manager class Client is closed in a finally block. Consider using 'with' statement.

Copilot uses AI. Check for mistakes.
@Adityarya11 Adityarya11 force-pushed the feat/e2e-custom-fee-royalty#1154 branch from e63921e to bc0f378 Compare December 19, 2025 10:27
@github-actions
Copy link

[commit-verification-bot]
Hi, this is VerificationBot.
Your pull request cannot be merged as it has unverified commits.
View your commit verification status: Commits Tab.

To achieve verified status, please read:

Remember, you require a GPG key and each commit must be signed with:
git commit -S -s -m "Your message here"

Thank you for contributing!

From the Hiero Python SDK Team

Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

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

Hi some of your commit are co authored by copilot, but i don't think its set up correctly with your GPG key as all your commits are not signed correctly
https://github.com/hiero-ledger/hiero-sdk-python/pull/1155/commits

would suggest soft reverting + starting fresh

@Adityarya11
Copy link
Contributor Author

Adityarya11 commented Dec 19, 2025

hi @exploreriii
i will be closing this PR and will reopen to start afresh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transform examples/tokens/custom_royalty_fee.py to be an end-to-end example

2 participants