Skip to content

Commit edd68e2

Browse files
committed
chore: updated example to use account_id dynamically
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 3eb3c14 commit edd68e2

5 files changed

Lines changed: 31 additions & 15 deletions

File tree

.github/workflows/pr-check-secondary-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Prepare Hiero Solo
3636
id: solo
37-
uses: hiero-ledger/hiero-solo-action@328bc84c3b00a990a151418144fd682a4eb76ea6 #v0.15.0
37+
uses: hiero-ledger/hiero-solo-action@328bc84c3b00a990a151418144fd682a4eb76ea6 #v0.19.0
3838
with:
3939
installMirrorNode: true
4040
- name: Run Examples

.github/workflows/pr-check-secondary-unit-integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129

130130
- name: Prepare Hiero Solo
131131
id: solo
132-
uses: hiero-ledger/hiero-solo-action@328bc84c3b00a990a151418144fd682a4eb76ea6 # v0.15.0
132+
uses: hiero-ledger/hiero-solo-action@328bc84c3b00a990a151418144fd682a4eb76ea6 # v0.19.0
133133
with:
134134
installMirrorNode: true
135135

examples/nodes/node_create_transaction.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
from dotenv import load_dotenv
2424

2525
from hiero_sdk_python import AccountId, Client, Network, PrivateKey
26+
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
2627
from hiero_sdk_python.address_book.endpoint import Endpoint
28+
from hiero_sdk_python.hbar import Hbar
2729
from hiero_sdk_python.nodes.node_create_transaction import NodeCreateTransaction
2830
from hiero_sdk_python.response_code import ResponseCode
2931

@@ -65,7 +67,12 @@ def node_create():
6567

6668
# Node account ID - this should be an existing account
6769
# that will be associated with the node
68-
account_id = AccountId.from_string("0.0.4")
70+
account_id = (
71+
AccountCreateTransaction()
72+
.set_key_without_alias(PrivateKey.generate_ed25519())
73+
.set_initial_balance(Hbar(1))
74+
.execute(client)
75+
).account_id
6976

7077
# Node description
7178
description = "Example node"

examples/nodes/node_delete_transaction.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
from dotenv import load_dotenv
2424

2525
from hiero_sdk_python import AccountId, Client, Network, PrivateKey
26+
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
2627
from hiero_sdk_python.address_book.endpoint import Endpoint
28+
from hiero_sdk_python.hbar import Hbar
2729
from hiero_sdk_python.nodes.node_create_transaction import NodeCreateTransaction
2830
from hiero_sdk_python.nodes.node_delete_transaction import NodeDeleteTransaction
2931
from hiero_sdk_python.response_code import ResponseCode
@@ -64,7 +66,12 @@ def create_node(client):
6466
"""Create a node on the network and return its ID and admin key."""
6567
# Node account ID - this should be an existing account
6668
# that will be associated with the node
67-
account_id = AccountId.from_string("0.0.4")
69+
account_id = (
70+
AccountCreateTransaction()
71+
.set_key_without_alias(PrivateKey.generate_ed25519())
72+
.set_initial_balance(Hbar(1))
73+
.execute(client)
74+
).account_id
6875

6976
# Node description
7077
description = "Example node for deletion"

examples/nodes/node_update_transaction.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
from dotenv import load_dotenv
2424

2525
from hiero_sdk_python import AccountId, Client, Network, PrivateKey
26+
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
2627
from hiero_sdk_python.address_book.endpoint import Endpoint
28+
from hiero_sdk_python.hbar import Hbar
2729
from hiero_sdk_python.nodes.node_create_transaction import NodeCreateTransaction
2830
from hiero_sdk_python.nodes.node_update_transaction import NodeUpdateTransaction
2931
from hiero_sdk_python.response_code import ResponseCode
@@ -60,12 +62,8 @@ def setup_client():
6062
return client
6163

6264

63-
def create_node(client):
65+
def create_node(client, account_id):
6466
"""Create a node on the network and return its ID and admin key."""
65-
# Node account ID - this should be an existing account
66-
# that will be associated with the node
67-
account_id = AccountId.from_string("0.0.4")
68-
6967
# Node description
7068
description = "Example node"
7169

@@ -108,11 +106,8 @@ def create_node(client):
108106
return receipt.node_id, admin_key
109107

110108

111-
def update_node(client, node_id, admin_key):
109+
def update_node(client, node_id, admin_key, account_id, node_account_pk):
112110
"""Update an existing node with new parameters."""
113-
# Node account ID
114-
account_id = AccountId.from_string("0.0.4")
115-
116111
# Updated node description
117112
updated_description = "Updated example node"
118113

@@ -140,6 +135,7 @@ def update_node(client, node_id, admin_key):
140135
.set_decline_reward(False)
141136
.freeze_with(client)
142137
.sign(admin_key) # Sign with the admin key
138+
.sign(node_account_pk)
143139
.execute(client)
144140
)
145141

@@ -163,11 +159,17 @@ def node_update():
163159
# Set up client with operator account
164160
client = setup_client()
165161

162+
# Node account ID
163+
node_account_pk = PrivateKey.generate_ed25519()
164+
account_id = (
165+
AccountCreateTransaction().set_key_without_alias(node_account_pk).set_initial_balance(Hbar(1)).execute(client)
166+
).account_id
167+
166168
# Create a new node and get its ID and admin key
167-
node_id, admin_key = create_node(client)
169+
node_id, admin_key = create_node(client, account_id)
168170

169171
# Update the newly created node with modified parameters
170-
update_node(client, node_id, admin_key)
172+
update_node(client, node_id, admin_key, account_id, node_account_pk)
171173

172174
print("\nNode creation and update example completed successfully!")
173175

0 commit comments

Comments
 (0)