Skip to content

Add TokenRejectFlow to reject and dissociate tokens in one call #2785

Open

Description

@danielmarv

🐞 Problem Description

Rejecting tokens with the Python SDK takes two transactions:

  1. A TokenRejectTransaction that sends the fungible tokens and/or NFTs back to the treasury.
  2. A TokenDissociateTransaction that removes the now-empty token relationships from the owner account.

Users have to build, sign and execute both themselves, and work out which token IDs to dissociate (including the token IDs behind any rejected NFTs).

The Java and JS SDKs provide TokenRejectFlow, which does both steps in one call. The Python SDK has nothing equivalent, so this is a feature gap.

Note: #22 ("Add TokenRejectFlow") was closed as not planned in Nov 2024 with no description. TokenRejectTransaction exists now, so the flow can be built on top of it.

💡 Expected Solution

Add a TokenRejectFlow class that runs reject → dissociate in a single execute(client) call, with the same builder-style API as the other SDKs.

receipt = (
    TokenRejectFlow()
    .set_owner_id(owner_id)
    .add_token_id(fungible_token_id)
    .add_nft_id(NftId(nft_token_id, 1))
    .freeze_with(client)
    .sign(owner_private_key)
    .execute(client)
)

🛠️ Implementation Notes

  • Add src/hiero_sdk_python/tokens/token_reject_flow.py with these fields:
    owner_id: AccountId | None = None
    token_ids: list[TokenId] = []
    nft_ids: list[NftId] = []
    node_account_ids: list[AccountId] | None = None
    _freeze_with_client: Client | None = None
    _sign_private_key: PrivateKey | None = None
    _sign_public_key: PublicKey | None = None
    _transaction_signer: Signer | None = None
  • Add setters that return self: set_owner_id, set_token_ids, add_token_id, set_nft_ids, add_nft_id, set_node_account_ids. Lists should be copied, not stored by reference.
  • Add freeze_with(client), sign(private_key), sign_with(public_key, signer) and sign_with_operator(client). They should store the client or signer, and setting one signing option should clear the others (same as the Java implementation and the ContractCreateFlow design in Add ContractCreateFlow to simplify smart contract deployment #2776).
  • Add a private helper that applies node_account_ids, freeze_with and the stored signer to a transaction. Use it for both inner transactions.
  • Add execute(client):
    1. Build and run a TokenRejectTransaction (set_owner_id, set_token_ids, set_nft_ids) and wait for its receipt.
    2. Build and run a TokenDissociateTransaction for owner_id. Its token list is token_ids plus the token_id of every entry in nft_ids, de-duplicated with order kept. Wait for its receipt.
    3. Return the result of the reject transaction. Python's Transaction.execute returns a TransactionReceipt by default, so return the reject receipt. This matches Add ContractCreateFlow to simplify smart contract deployment #2776.
    4. If either receipt has a status other than SUCCESS, raise the SDK's existing receipt error. Don't swallow it.
  • Validate types and values in the setters and in execute (for example, owner_id is required and at least one token or NFT must be given).
  • Export TokenRejectFlow from hiero_sdk_python/__init__.py.
  • Add an example at examples/tokens/token_reject_flow.py.

Async execution is out of scope.

🧪 Testing

  • Unit tests (tests/unit/): setter chaining and validation, de-duplication of dissociate token IDs (fungible plus NFT from the same token), signer options overriding each other, and that both inner transactions get the node IDs, freeze client and signer.
  • Integration test (tests/integration/): an account associated with a fungible token and an NFT collection rejects both. Check that the balances go back to the treasury and that the account is no longer associated with either token.

✅ Acceptance Criteria

  • TokenRejectFlow is importable from hiero_sdk_python
  • One execute(client) call rejects and dissociates
  • Unit and integration tests pass
  • Example added under examples/tokens/

📚 References

Activity

  1. added
    skill: intermediaterequires some knowledge of the codebase with some defined steps to implement or examples
    scope: DLTinvolves engineering for distributed ledger technology
    pythonPull requests that update python code
    on Nov 12, 2026
  2. github-actions commented on Nov 12, 2026

    @github-actions

    Thanks for your submission.

    This issue is awaiting approval from @hiero-ledger/hiero-sdk-python-triage and @hiero-ledger/hiero-sdk-python-committers and @hiero-ledger/hiero-sdk-python-maintainers.

  3. locked as off topic and limited conversation to collaborators on Nov 12, 2026
  4. added
    approvedIssue has been approved by team member
    and removed on Nov 13, 2026
  5. unlocked this conversation on Nov 13, 2026
  6. github-actions commented on Nov 13, 2026

    @github-actions

    Approved by @hiero-ledger/hiero-sdk-python-triage and @hiero-ledger/hiero-sdk-python-committers and @hiero-ledger/hiero-sdk-python-maintainers.

  7. github-actions commented on Nov 13, 2026

    @github-actions
  8. Dhie-boop commented on Nov 13, 2026

    @Dhie-boop
    Contributor

    /assign

  9. github-actions commented on Nov 13, 2026

    @github-actions

    👋 Hi @Dhie-boop! Thanks for your interest in contributing 💡

    Before taking on a Intermediate issue, we ask contributors to complete at least 3 Beginner issues first.

    👉 Find one here

    Once you've done that, come back — we'll be happy to assign this! 😊

  10. achintya2k5 commented on Nov 13, 2026

    @achintya2k5
    Contributor

    /assign

  11. github-actions commented on Nov 21, 2026

    @github-actions

    Hi @achintya2k5 👋

    This issue has been assigned but no pull request has been created yet.
    Are you still planning on working on it?
    If you are, please create a draft PR linked to this issue or comment /working to let us know.
    If you're no longer able to work on this issue, you can comment /unassign to release it.

    From the Python SDK Team

  12. achintya2k5 commented on Nov 21, 2026

    @achintya2k5
    Contributor

    /working

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

Metadata

Metadata

Assignees

Labels

approvedIssue has been approved by team memberpythonPull requests that update python codescope: DLTinvolves engineering for distributed ledger technologyskill: intermediaterequires some knowledge of the codebase with some defined steps to implement or examples

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions