-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathonboard.py
41 lines (33 loc) · 1.19 KB
/
onboard.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
'''Example for onboarding an account and accessing private endpoints.
Usage: python -m examples.onboard
'''
from dydx3 import Client
from dydx3.constants import API_HOST_SEPOLIA
from dydx3.constants import NETWORK_ID_SEPOLIA
from web3 import Web3
# Ganache test address.
ETHEREUM_ADDRESS = '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b'
# Ganache node.
WEB_PROVIDER_URL = 'http://localhost:8545'
client = Client(
network_id=NETWORK_ID_SEPOLIA,
host=API_HOST_SEPOLIA,
default_ethereum_address=ETHEREUM_ADDRESS,
web3=Web3(Web3.HTTPProvider(WEB_PROVIDER_URL)),
)
# Set STARK key.
stark_key_pair_with_y_coordinate = client.onboarding.derive_stark_key()
client.stark_private_key = stark_key_pair_with_y_coordinate['private_key']
(public_x, public_y) = (
stark_key_pair_with_y_coordinate['public_key'],
stark_key_pair_with_y_coordinate['public_key_y_coordinate'],
)
# Onboard the account.
onboarding_response = client.onboarding.create_user(
stark_public_key=public_x,
stark_public_key_y_coordinate=public_y,
)
print('onboarding_response', onboarding_response)
# Query a private endpoint.
accounts_response = client.private.get_accounts()
print('accounts_response', accounts_response)