Skip to content

Conversation

@CynthiaFotso
Copy link
Contributor

Description

This PR adds a beginner-friendly documentation page explaining the transaction lifecycle in the Python SDK.

Linked Issue

Fixes #864: Create docs/sdk_developers/training/transaction_lifecycle.md

Checklist

  • Created docs/sdk_developers/training/transaction_lifecycle.md

  • Overview of the transaction flow (construct → freeze → sign → execute → check receipt)

  • Detailed explanation of each step, including why the order matters

  • Code examples using both Pythonic and method chaining syntax

  • A simple flow diagram

  • Common pitfalls and best practices

  • Referenced existing examples like examples/token_grant_kyc.py and examples/token_associate.py

Signed-off-by: Cynthia Fotso <cynthiafotso8@gmail.com>
Signed-off-by: Cynthia Fotso <cynthiafotso8@gmail.com>
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.

Wow ! excellent work!
we have one issue - we don't yet have a get receipt method in the python sdk

currently executing it will also get you a receipt

Fetch and verify the transaction receipt to confirm processing.

```python
receipt = response.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.

so right now as raised in issue
#398
we don't have a separate receipt step in the python sdk

i.e. this will currently get you a receipt
response = transaction.execute(client)

which is why you see
receipt = transaction.execute(client)
if receipt.status != ResponseCode.SUCCESS:
print(f"Transaction failed: {ResponseCode(receipt.status).name}")
else:
print("Transaction successful!")

print("Transaction successful!")
```

- **Why check?** Receipts provide the final status and any generated IDs (e.g., new account ID).
Copy link
Contributor

Choose a reason for hiding this comment

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

this part is really important to emphasise -
you must check the receipt for SUCCESS to know if hedera processed the transaction as you wanted

sometimes it can throw up errors (list some.. they are written at src/hiero_sdk_python/response_code.py
but will still process the transaction with that failure

ie your python code won't catch on to any errors unless you check the receipt

.freeze_with(client) # Lock fields
.sign(account_private_key) # Authorize
.execute(client) # Submit to Hedera
.get_receipt(client) # Fetch result
Copy link
Contributor

Choose a reason for hiding this comment

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

delete line 111 - not yet part of the python sdk

### Correct
```python
transaction = TokenAssociateTransaction().set_account_id(account_id).freeze_with(client).sign(key).execute(client)
receipt = response.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.

remember we do not use get receipt currently

execute will return a receipt for us
(see examples)

receipt = response.get_receipt(client) <- no

@exploreriii
Copy link
Contributor

Hi @CynthiaFotso please rebase to pull in main's changes, we applied a fix that was blocking our tests.

@exploreriii
Copy link
Contributor

Hi @CynthiaFotso please do let us know if we can be of assistance

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.

Create docs/sdk_developers/training/transaction_lifecycle.md

2 participants