forked from decibeltrade/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_subaccount.py
More file actions
51 lines (39 loc) · 1.23 KB
/
create_subaccount.py
File metadata and controls
51 lines (39 loc) · 1.23 KB
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
44
45
46
47
48
49
50
51
import asyncio
import os
from aptos_sdk.account import Account
from aptos_sdk.ed25519 import PrivateKey
from decibel import (
NETNA_CONFIG,
BaseSDKOptions,
DecibelWriteDex,
GasPriceManager,
)
async def main() -> None:
private_key = PrivateKey.from_hex(os.environ["PRIVATE_KEY"])
account = Account.load_key(private_key.hex())
gas = GasPriceManager(NETNA_CONFIG)
await gas.initialize()
write = DecibelWriteDex(
NETNA_CONFIG,
account,
opts=BaseSDKOptions(
node_api_key=os.environ.get("APTOS_NODE_API_KEY"),
gas_price_manager=gas,
skip_simulate=False,
no_fee_payer=True,
time_delta_ms=0,
),
)
tx_result = await write.create_subaccount()
print(f"Transaction hash: {tx_result.get('hash')}")
events = tx_result.get("events", [])
for event in events:
event_type = event.get("type", "")
if "SubaccountCreatedEvent" in event_type:
event_data = event.get("data", {})
subaccount_addr = event_data.get("subaccount")
print(f"New subaccount created: {subaccount_addr}")
break
await gas.destroy()
if __name__ == "__main__":
asyncio.run(main())