Skip to content

Commit 3dc1593

Browse files
committed
chore: rearrange module 5 and 6 for imports
Signed-off-by: exploreriii <133720349+exploreriii@users.noreply.github.com>
1 parent 40f5b36 commit 3dc1593

File tree

3 files changed

+78
-44
lines changed

3 files changed

+78
-44
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## Setup Network and Client
2+
3+
All transactions and queries on the Hedera network require a network and client set-up.
4+
5+
To do this you'll need to import the relevant functionality, variables from .env and attach them to the Network and Client classes as appropriate.
6+
7+
### Worked Example
8+
```python
9+
import sys
10+
from dotenv import load_dotenv
11+
from os import getenv
12+
13+
from hiero_sdk_python.account.account_id import AccountId
14+
from hiero_sdk_python.crypto.private_key import PrivateKey
15+
from hiero_sdk_python.client.client import Client
16+
from hiero_sdk_python.client.network import Network
17+
from hiero_sdk_python.tokens.token_create_transaction import TokenCreateTransaction
18+
from hiero_sdk_python.client import client
19+
from hiero_sdk_python.response_code import ResponseCode
20+
21+
# 1. Setup Client
22+
load_dotenv()
23+
operator_id = AccountId.from_string(getenv('OPERATOR_ID',''))
24+
operator_key = PrivateKey.from_string(getenv('OPERATOR_KEY',''))
25+
26+
network = Network(getenv('NETWORK',''))
27+
client = Client(network)
28+
client.set_operator(operator_id, operator_key)
29+
30+
# 2. Build the transaction
31+
create_tx = (
32+
TokenCreateTransaction()
33+
.set_token_name("Example Token")
34+
.set_token_symbol("EXT")
35+
.set_treasury_account_id(operator_id)
36+
.set_initial_supply(100000)
37+
.freeze_with(client)
38+
.sign(operator_key)
39+
)
40+
41+
# 3. Execute and get receipt
42+
receipt = create_tx.execute(client)
43+
44+
# 4. Validate Success
45+
if receipt.status != ResponseCode.SUCCESS:
46+
print(f"Token creation on Hedera failed: {ResponseCode(receipt.status).name}")
47+
sys.exit(1)
48+
49+
# 5. Extract the Token ID
50+
token_id = receipt.token_id
51+
print(f"🎉 Created new token on the Hedera network with ID: {token_id}")
52+
```
53+
54+
### Extra Support
55+
Read about Network and Client in more detail [here](docs/sdk_developers/training/network_and_client.md)

docs/sdk_developers/training/setup/05_importing_hiero_files.md renamed to docs/sdk_developers/training/setup/06_importing_hiero_files.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,49 @@ from hiero_sdk_python.tokens import token_create_transaction
2121
### Advanced Example
2222
You'll need to import everything you require.
2323

24-
In this more advanced example, we are using: sys, TokenCreateTransaction, Client and ResponseCode.
24+
In this more advanced example, we are using imports to load env, to set up the client and network, and to form the Token Create Transaction and check the response:
25+
2526
```python
2627
import sys
28+
from dotenv import load_dotenv
29+
from os import getenv
30+
31+
from hiero_sdk_python.account.account_id import AccountId
32+
from hiero_sdk_python.crypto.private_key import PrivateKey
33+
from hiero_sdk_python.client.client import Client
34+
from hiero_sdk_python.client.network import Network
2735
from hiero_sdk_python.tokens.token_create_transaction import TokenCreateTransaction
28-
from hiero_sdk_python.client import client
2936
from hiero_sdk_python.response_code import ResponseCode
3037

31-
# 1. Build the transaction
38+
# 1. Setup Client
39+
load_dotenv()
40+
operator_id = AccountId.from_string(getenv('OPERATOR_ID',''))
41+
operator_key = PrivateKey.from_string(getenv('OPERATOR_KEY',''))
42+
43+
network = Network(getenv('NETWORK',''))
44+
client = Client(network)
45+
client.set_operator(operator_id, operator_key)
46+
47+
# 2. Build the transaction
3248
create_tx = (
3349
TokenCreateTransaction()
3450
.set_token_name("Example Token")
3551
.set_token_symbol("EXT")
3652
.set_treasury_account_id(operator_id)
53+
.set_initial_supply(100000)
3754
.freeze_with(client)
3855
.sign(operator_key)
3956
)
4057

41-
# 2. Execute and get receipt
58+
# 3. Execute and get receipt
4259
receipt = create_tx.execute(client)
4360

44-
# 3. Validate Success
61+
# 4. Validate Success
4562
if receipt.status != ResponseCode.SUCCESS:
4663
print(f"Token creation on Hedera failed: {ResponseCode(receipt.status).name}")
4764
sys.exit(1)
4865

49-
# 4. Extract the Token ID
66+
# 5. Extract the Token ID
5067
token_id = receipt.token_id
5168
print(f"🎉 Created new token on the Hedera network with ID: {token_id}")
5269
```

docs/sdk_developers/training/setup/06_network_client_setup.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)