forked from hedera-dev/hedera-code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_gen.py
43 lines (34 loc) · 1.21 KB
/
account_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#Import module and classes
import os
from hedera import (
Client,
Hbar,
PrivateKey,
AccountCreateTransaction,
AccountId,
Client
)
#create function to generate account
def generate_account():
#Store the operator credentials
OPERATOR_ID = AccountId.fromString('Get yours on Hedera Portal')
OPERATOR_KEY = PrivateKey.fromString('Get yours on Hedera Portal')
#Create client class using Operator credentials
client = Client.forTestnet()
client.setOperator(OPERATOR_ID, OPERATOR_KEY)
#generate keys of the account with Hedera SDK Keys generator
newKey = PrivateKey.generate()
newPublicKey = newKey.getPublicKey()
#Execute Transaction of account creation
resp = (AccountCreateTransaction()
.setKey(newPublicKey)
.setInitialBalance(Hbar.fromTinybars(1000))
.execute(client))
#Get Receipt of previous transaction
receipt = resp.getReceipt(client)
#Get transaction ID of previous transaction
tx_id = receipt.transactionId.toString()
#Get keys of newly created account from Transaction receipt
account_id = receipt.accountId.toString()
account_key = receipt.key.toString()
return account_id, account_key