-
Notifications
You must be signed in to change notification settings - Fork 86
chore: Adapt custom_fee_royalty.py to be end-to-end #679 #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
chore: Adapt custom_fee_royalty.py to be end-to-end #679 #694
Conversation
|
hi @exploreriii i had tried to solve this issue can you check please |
There was a problem hiding this 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.
There was a problem hiding this 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>
899ba87 to
fe2b9f1
Compare
|
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 |
There was a problem hiding this 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
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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,
Fixes #679
Proposed Changes
This PR converts the
examples/custom_fee_royalty.pyscript into a complete end-to-end example that executes on the Hedera testnet.set_up_client,create_token_with_fee,query_token) for consistency with other Hiero SDK examples.CustomRoyaltyFee, and performs aTokenInfoQueryto verify the fee was successfully applied by the network.CHANGELOG.mdunder the### Changedsection.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