Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
- Improved type hinting in `file_append_transaction.py` to resolve 'mypy --strict` errors. ([#495](https://github.com/hiero-ledger/hiero-sdk-python/issues/495))
- fix: Resolve `__eq__` type conflict in `CustomFee` class (#627)
- Fixes a type conflict in `token_id.py` where `from_string` could receive `None`, preventing a runtime error by raising a `ValueError` if the input is missing. #630
- fix: Pass enum values directly to `TokenCreateTransaction` protobuf to fix type conflict


### Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions src/hiero_sdk_python/tokens/token_create_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ def _build_proto_body(self) -> token_create_pb2.TokenCreateTransactionBody:
symbol=self._token_params.token_symbol,
decimals=self._token_params.decimals,
initialSupply=self._token_params.initial_supply,
tokenType=token_type_value,
supplyType=supply_type_value,
tokenType=self._token_params.token_type.value,
Copy link
Contributor

@exploreriii exploreriii Nov 5, 2025

Choose a reason for hiding this comment

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

In lines 490 to 494 you see we have a function that attempts to resolve
token_type_value to be like the proto --

see:
token_type_value = (
self._token_params.token_type.value
if isinstance(self._token_params.token_type, TokenType)
else int(self._token_params.token_type or 0)
)

so when you suggest

tokenType=self_token_params.token_type.value
Its doing very similar thing

Current type error:
Argument of type "int" cannot be assigned to parameter "tokenType" of type "TokenType | str | None" in function "init"
  Type "int" is not assignable to type "TokenType | str | None"
    "int" is not assignable to "TokenType"
    "int" is not assignable to "str"
    "int" is not assignable to "None"

The reason this errors is because either the type checker is not able to pick up on the correct type in the proto, or the underlying protobuf expects tokenType: TokenType | str | None

Currently, it thinks we are passing ints, even if you delete the int normalisation (lines 490 to 494, and just provide your idea, it will still conflict as it would be type Literal[0,1]

SOLUTION
the solution is to cast the the token type to the proto value

This was per my original suggestion:
tokenType=basic_types_pb2.TokenType(self._token_params.token_type.value)

This works because its taken the token type enum Literal of [0,1] and wrapping it into the proto token type.

or
you can change lines 490 to 494, which in hindsight probably makes more sense
and do

    token_type_value = (
        self._token_params.token_type.value
        if isinstance(self._token_params.token_type, TokenType)
        else int(self._token_params.token_type or 0)
    )
    proto_token_type = basic_types_pb2.TokenType(token_type_value)

so it takes that token type literal and wraps it to proto friendly term

the underlying issue is we lack an easy to proto method for token type and supply type that would mean we can avoid writing all this custom conversions, and probably the type checker is not picking up on the type inference

Then we could just do
tokenType=self._token_params.token_type._to_proto()
and both the code will work (as it currently does) but the type checker will be happy too

Copy link
Contributor

@exploreriii exploreriii Nov 5, 2025

Choose a reason for hiding this comment

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

Currently testing if this would work,
My suggestion probably won't work
TypeError: 'EnumTypeWrapper' object is not callable
Not yet sure how to fix underlying issue, which seems to be caused by the type checker

@Pranay22077 can't find a way to fix the issue, let me know if you do! else feel free to start a new issue. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure @exploreriii
That's becoming a little too complex
Will update you about it in some time, after trying other steps

supplyType=self._token_params.supply_type.value,
maxSupply=self._token_params.max_supply,
freezeDefault=self._token_params.freeze_default,
treasury=self._token_params.treasury_account_id._to_proto(),
Expand Down