Skip to content

Commit 70d7eae

Browse files
committed
feat: hbar support
Signed-off-by: prajeeta pal <[email protected]>
1 parent 45519c2 commit 70d7eae

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

CHANGELOG.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
66

77
## [Unreleased]
88

9-
10-
119
### Added
10+
1211
- Added `__str__` and `__repr__` methods to `AccountInfo` class for improved logging and debugging experience (#1098)
1312
- Added Good First Issue (GFI) management and frequency documentation to clarify maintainer expectations and SDK-level GFI governance.
1413
- Added SDK-level Good First Issue (GFI) guidelines for maintainers to clarify what qualifies as a good first issue.
@@ -20,7 +19,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2019
- Added unit tests for `SubscriptionHandle` class covering cancellation state, thread management, and join operations.
2120
- Refactored `account_create_transaction_create_with_alias.py` example by splitting monolithic function into modular functions: `generate_main_and_alias_keys()`, `create_account_with_ecdsa_alias()`, `fetch_account_info()`, `print_account_summary()` (#1016)
2221
- Added `.github/workflows/bot-pr-auto-draft-on-changes.yml` to automatically convert PRs to draft and notify authors when reviewers request changes.
23-
-
22+
-
2423
- Modularized `transfer_transaction_fungible` example by introducing `account_balance_query()` & `transfer_transaction()`.Renamed `transfer_tokens()``main()`
2524
- Phase 2 of the inactivity-unassign bot: Automatically detects stale open pull requests (no commit activity for 21+ days), comments with a helpful InactivityBot message, closes the stale PR, and unassigns the contributor from the linked issue.
2625
- Added `__str__()` to CustomFixedFee and updated examples and tests accordingly.
@@ -39,14 +38,16 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
3938
- Support selecting specific node account ID(s) for queries and transactions and added `Network._get_node()` with updated execution flow (#362)
4039
- Add TLS support with two-stage control (`set_transport_security()` and `set_verify_certificates()`) for encrypted connections to Hedera networks. TLS is enabled by default for hosted networks (mainnet, testnet, previewnet) and disabled for local networks (solo, localhost) (#855)
4140
- Add PR inactivity reminder bot for stale pull requests `.github/workflows/pr-inactivity-reminder-bot.yml`
42-
- Add comprehensive training documentation for _Executable class `docs/sdk_developers/training/executable.md`
41+
- Add comprehensive training documentation for \_Executable class `docs/sdk_developers/training/executable.md`
4342
- Added empty `docs/maintainers/good_first_issues.md` file for maintainers to write Good First Issue guidelines (#1034)
4443
- Added new `.github/ISSUE_TEMPLATE/04_good_first_issue_candidate.yml` file (1068)(https://github.com/hiero-ledger/hiero-sdk-python/issues/1068)
4544
- Enhanced `.github/ISSUE_TEMPLATE/01_good_first_issue.yml` with welcoming message and acceptance criteria sections to guide contributors in creating quality GFIs (#1052)
4645
- Add workflow to notify team about P0 issues `bot-p0-issues-notify-team.yml`
4746
- Added Issue Reminder (no-PR) bot, .github/scripts/issue_reminder_no_pr.sh and .github/workflows/bot-issue-reminder-no-pr.yml to automatically detect assigned issues with no linked pull requests for 7+ days and post a gentle ReminderBot comment.(#951)
47+
- Added `add_hbar_transfer`, `add_approved_hbar_transfer`, and internal `_add_hbar_transfer` to accept `Hbar` objects in addition to raw tinybar integers, with internal normalization to tinybars. Added tests validating the new behavior.
4848

4949
### Changed
50+
5051
- Improved consistency of transaction examples (#1120)
5152
- Refactored `account_create_transaction_with_fallback_alias.py` by splitting the monolithic `create_account_with_fallback_alias` function into modular functions: `generate_fallback_key`, `fetch_account_info`, and `print_account_summary`. The existing `setup_client()` function was reused for improved readability and structure (#1018)
5253
- Allow `PublicKey` for `TokenUpdateKeys` in `TokenUpdateTransaction`, enabling non-custodial workflows where operators can build transactions using only public keys (#934).
@@ -62,10 +63,9 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
6263
- Cleaned up `token_airdrop_claim_auto` example for pylint compliance (no functional changes). (#1079)
6364
- Formatted `examples/query` using black (#1082)(https://github.com/hiero-ledger/hiero-sdk-python/issues/1082)
6465
- Update team notification script and workflow for P0 issues 'p0_issues_notify_team.js'
65-
- Rename test files across the repository to ensure they consistently end with _test.py (#1055)
66+
- Rename test files across the repository to ensure they consistently end with \_test.py (#1055)
6667
- Cleaned up `token_airdrop_claim_signature_required` example for pylint compliance (no functional changes). (#1080)
67-
- Rename the file 'test_token_fee_schedule_update_transaction_e2e.py' to make it ends with _test.py as all other test files.(#1117)
68-
68+
- Rename the file 'test_token_fee_schedule_update_transaction_e2e.py' to make it ends with \_test.py as all other test files.(#1117)
6969

7070
### Fixed
7171

@@ -92,8 +92,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
9292
- Added `.github/workflows/merge-conflict-bot.yml` to automatically detect and notify users of merge conflicts in Pull Requests.
9393
- Added `.github/workflows/bot-office-hours.yml` to automate the Weekly Office Hour Reminder.
9494
- feat: Implement account creation with EVM-style alias transaction example.
95-
- Added validation logic in `.github/workflows/pr-checks.yml` to detect when no new changelog entries are added under [Unreleased]
96-
- feat: Allow `add_hbar_transfer`, `add_approved_hbar_transfer`, and internal `_add_hbar_transfer` to accept `Hbar` objects in addition to raw tinybar integers, with internal normalization to tinybars. Added tests validating the new behavior.
95+
- Added validation logic in `.github/workflows/pr-checks.yml` to detect when no new changelog entries are added under [Unreleased].
96+
- Support for message chunking in `TopicSubmitMessageTransaction`.
9797

9898
### Changed
9999

@@ -645,4 +645,3 @@ contract_call_local_pb2.ContractLoginfo -> contract_types_pb2.ContractLoginfo
645645
### Removed
646646

647647
- N/A
648-

src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ def _add_token_transfer(
148148
raise TypeError("token_id must be a TokenId instance.")
149149
if not isinstance(account_id, AccountId):
150150
raise TypeError("account_id must be an AccountId instance.")
151-
if not isinstance(amount, int) or amount == 0:
152-
raise ValueError("Amount must be a integer.")
151+
if not isinstance(amount, int):
152+
raise TypeError("Amount must be an integer.")
153153
if amount == 0:
154-
raise ValueError("amount must be a non-zero value.")
154+
raise ValueError("Amount must be a non-zero value.")
155155
if expected_decimals is not None and not isinstance(expected_decimals, int):
156156
raise TypeError("expected_decimals must be an integer.")
157157
if not isinstance(is_approved, bool):

src/hiero_sdk_python/transaction/transfer_transaction.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
Defines TransferTransaction for transferring HBAR or tokens between accounts.
33
"""
44

5-
from typing import Dict, List, Optional, Tuple
5+
from typing import Dict, List, Optional, Tuple, Union
66

77
from hiero_sdk_python.account.account_id import AccountId
88
from hiero_sdk_python.channels import _Channel
99
from hiero_sdk_python.executable import _Method
10+
from hiero_sdk_python.hbar import Hbar
1011
from hiero_sdk_python.hapi.services import basic_types_pb2, crypto_transfer_pb2, transaction_pb2
1112
from hiero_sdk_python.hapi.services.schedulable_transaction_body_pb2 import (
1213
SchedulableTransactionBody,
@@ -60,14 +61,14 @@ def _init_hbar_transfers(self, hbar_transfers: Dict[AccountId, int]) -> None:
6061
self.add_hbar_transfer(account_id, amount)
6162

6263
def _add_hbar_transfer(
63-
self, account_id: AccountId, amount: int, is_approved: bool = False
64+
self, account_id: AccountId, amount: Union[int, Hbar], is_approved: bool = False
6465
) -> "TransferTransaction":
6566
"""
6667
Internal method to add a HBAR transfer to the transaction.
6768
6869
Args:
6970
account_id (AccountId): The account ID of the sender or receiver.
70-
amount (int): The amount of the HBAR to transfer.
71+
amount (Union[int, Hbar]): The amount of the HBAR to transfer (in tinybars if int, or Hbar object).
7172
is_approved (bool, optional): Whether the transfer is approved. Defaults to False.
7273
7374
Returns:
@@ -81,11 +82,13 @@ def _add_hbar_transfer(
8182
if amount is None:
8283
raise TypeError("amount cannot be None.")
8384

84-
if not isinstance(amount, int):
85-
raise TypeError("amount must be an integer.")
85+
if isinstance(amount, Hbar):
86+
amount = amount.to_tinybars()
87+
elif not isinstance(amount, int):
88+
raise TypeError("amount must be an integer or Hbar object.")
8689

8790
if amount == 0:
88-
raise ValueError("amount must be a non-zero integer.")
91+
raise ValueError("Amount must be a non-zero value.")
8992

9093
if not isinstance(is_approved, bool):
9194
raise TypeError("is_approved must be a boolean.")
@@ -95,17 +98,17 @@ def _add_hbar_transfer(
9598
transfer.amount += amount
9699
return self
97100

98-
self.hbar_transfers.append(
99-
HbarTransfer(account_id, amount, is_approved))
100-
return self
101+
self.hbar_transfers.append(
102+
HbarTransfer(account_id, amount, is_approved))
103+
return self
101104

102-
def add_hbar_transfer(self, account_id: AccountId, amount: int) -> "TransferTransaction":
105+
def add_hbar_transfer(self, account_id: AccountId, amount: Union[int, Hbar]) -> "TransferTransaction":
103106
"""
104107
Adds a HBAR transfer to the transaction.
105108
106109
Args:
107110
account_id (AccountId): The account ID of the sender or receiver.
108-
amount (int): The amount of the HBAR to transfer.
111+
amount (Union[int, Hbar]): The amount of the HBAR to transfer (in tinybars if int, or Hbar object).
109112
110113
Returns:
111114
TransferTransaction: The current instance of the transaction for chaining.
@@ -114,14 +117,14 @@ def add_hbar_transfer(self, account_id: AccountId, amount: int) -> "TransferTran
114117
return self
115118

116119
def add_approved_hbar_transfer(
117-
self, account_id: AccountId, amount: int
120+
self, account_id: AccountId, amount: Union[int, Hbar]
118121
) -> "TransferTransaction":
119122
"""
120123
Adds a HBAR transfer with approval to the transaction.
121124
122125
Args:
123126
account_id (AccountId): The account ID of the sender or receiver.
124-
amount (int): The amount of the HBAR to transfer.
127+
amount (Union[int, Hbar]): The amount of the HBAR to transfer (in tinybars if int, or Hbar object).
125128
126129
Returns:
127130
TransferTransaction: The current instance of the transaction for chaining.

0 commit comments

Comments
 (0)