Skip to content

Conversation

@prakhar14-op
Copy link
Contributor

Fixes #679

Proposed Changes

This PR converts the examples/custom_fee_royalty.py script into a complete end-to-end example that executes on the Hedera testnet.

  • Refactoring: The original local object-building logic was replaced with modular functions (set_up_client, create_token_with_fee, query_token) for consistency with other Hiero SDK examples.
  • Functionality: The script now connects to the network, creates a new NFT with the defined CustomRoyaltyFee, and performs a TokenInfoQuery to verify the fee was successfully applied by the network.
  • Changelog: Adds the required entry to CHANGELOG.md under the ### Changed section.

Implementation Details

The implementation reuses utility functions from existing examples (set_up_client) and correctly structures the token creation process specifically for a Non-Fungible Unique token, as royalty fees require.

Checklist

  • I have read the CONTRIBUTING.md
  • I have signed the commit for DCO and GPG.

@prakhar14-op
Copy link
Contributor Author

hi @exploreriii i had tried to solve this issue can you check please

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 @prakhar14-op
Good try but did you know you can run the script to verify if it works?
Read README.md for instructions on setting up a hedera portal account and setting up your env. files with the correct information.

Once you can run it, you can verify if it works.

Currently, it will not run because your imports for the files needed are incorrect

from hiero_sdk_python.custom_fees.custom_royalty_fee import CustomRoyaltyFee
->
from hiero_sdk_python.tokens.custom_royalty_fee import CustomRoyaltyFee

from hiero_sdk_python.token.token_create_transaction import TokenCreateTransaction
->
from hiero_sdk_python.tokens.token_create_transaction import TokenCreateTransaction

You should set up your VS code so it warns you if something is not correct
you can see all the other incorrect imports are not indexed in green, thus, there is an error, and you should correct them.

All the examples are in the same file, so, you can just copy how other examples import files and use that.

Image

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.

Please do not auto-generate content, use the methods that exist and are demonstrated in each of our files if in doubt.
When running the script it will not run until you only use stuff that exists

Signed-off-by: Prakhar Sharma <prakharsharma_mc24b06_001@dtu.ac.in>
@prakhar14-op prakhar14-op force-pushed the feat/royalty-fee-e2e-example-679 branch from 899ba87 to fe2b9f1 Compare October 31, 2025 16:41
@exploreriii
Copy link
Contributor

exploreriii commented Oct 31, 2025

Hi, the review is the example still doesn't run, the main issue is the imports are not correct.

What I would recommend is getting in touch and I can explain what to do

discord.md
MAINTAINERS.md

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.

Sorry to hear you were unwell

I am happy to provide some feedback for you, I recommend you contact us on discord.md if you have questions or want help.

Your example script is pretty good, but it will not run.

The reason it will not run is you are using some invalid functions and invalid imports that are not part of our SDK (see attachments)

This means that it can't load the data it needs to run.

Please read docs/sdk_developers/pylance.md and project_structure.md, install it and you'll get these warnings too

Image Image

For example
from hiero_sdk_python.custom_fees.custom_royalty_fee import CustomRoyaltyFee

should be
from hiero_sdk_python.tokens.custom_royalty_fee import CustomRoyaltyFee

So you need to import the file from the right place that corresponds to our project structure

Review other examples and see how they import.

from hiero_sdk_python.key.key import Key
from hiero_sdk_python.hbar.hbar import Hbar

def set_up_client() -> Client:
Copy link
Contributor

Choose a reason for hiding this comment

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

def setup_client():
"""Initialize and set up the client with operator account"""
network = Network(os.getenv('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)

return client

operator_id = client.operator_account_id
operator_key = client.operator_private_key

# Create the TokenCreateTransaction
Copy link
Contributor

Choose a reason for hiding this comment

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

this will all fail

tx = TokenCreateTransaction(
    token_name="My Royalty NFT",
    token_symbol="MRNFT",
    token_type=TokenType.NON_FUNGIBLE_UNIQUE,
    supply_type=TokenSupplyType.FINITE,
    treasury_account_id=operator_id,
    # Add the custom fee we defined
    custom_fees=[fee],
    admin_key=operator_key,
    supply_key=operator_key,
    max_supply=100,
    # Set transaction fee
    max_transaction_fee=Hbar(30) 
)

Search for any other TokenCreateTransaction example and notice they tend to use

.set_token_name
.set_etc

That's because if you look at the code for src/hiero_sdk_python/tokens/token_create_transaction.py
you'll see it allows you to use setters

but if you instead want to pass parameters directly (like your attempt), you need to pass it in the way the class allows, which would actually be:

1. Define your token parameters

token_params = TokenParams(
token_name="My Royalty NFT",
token_symbol="MRNFT",
treasury_account_id=operator_id,
token_type=TokenType.NON_FUNGIBLE_UNIQUE,
supply_type=SupplyType.FINITE,
max_supply=100,
custom_fees=[fee],
)

2. Define your token keys

token_keys = TokenKeys(
admin_key=operator_key,
supply_key=operator_key
)

3. Create the TokenCreateTransaction

tx = TokenCreateTransaction(
token_params=token_params,
keys=token_keys
)
like this

Copy link
Contributor

Choose a reason for hiding this comment

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

note we don't have functionality in token create for you to create a max_transaction_fee so that won't work either

from hiero_sdk_python.tokens.custom_fixed_fee import CustomFixedFee
from hiero_sdk_python.tokens.custom_royalty_fee import CustomRoyaltyFee

import os
Copy link
Contributor

Choose a reason for hiding this comment

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

you're missing some key imports that you are using, for example
import sys


# Sign and execute
submitted_tx = tx.execute(client)
receipt = submitted_tx.get_receipt(client)
Copy link
Contributor

Choose a reason for hiding this comment

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

get_receipt is not something we do

we do more like this:
check out other examples for token create and you'll see this

    # .set_max_transaction_fee(Hbar(30))  # Set transaction fee
    .execute(client)
)

if receipt.status != ResponseCode.SUCCESS:
    print(f"NFT token creation failed with status: {ResponseCode(receipt.status).name}")
    sys.exit(1)

token_id = receipt.token_id
print(f"NFT token created with ID: {token_id}")
return token_id

treasury_account_id=operator_id,
# Add the custom fee we defined
custom_fees=[fee],
admin_key=operator_key,
Copy link
Contributor

Choose a reason for hiding this comment

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

you do not need an admin key, i think
admin_key=operator_key,

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.

Adapt examples/custom_fee_royalty.py to be end to end

2 participants