forked from lsuanet/dydx-v3-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonboard.py
39 lines (31 loc) · 1.13 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
'''Example for onboarding an account and accessing private endpoints.
Usage: python -m examples.onboard
'''
from dydx3 import Client
from dydx3 import private_key_to_public_key_pair_hex
from dydx3.constants import API_HOST_ROPSTEN
from dydx3.constants import NETWORK_ID_ROPSTEN
from web3 import Web3
# Ganache test address.
ETHEREUM_ADDRESS = '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b'
# Ganache node.
WEB_PROVIDER_URL = 'http://localhost:8545'
client = Client(
network_id=NETWORK_ID_ROPSTEN,
host=API_HOST_ROPSTEN,
default_ethereum_address=ETHEREUM_ADDRESS,
web3=Web3(Web3.HTTPProvider(WEB_PROVIDER_URL)),
)
# Set STARK key.
stark_private_key = client.onboarding.derive_stark_key()
client.stark_private_key = stark_private_key
public_x, public_y = private_key_to_public_key_pair_hex(stark_private_key)
# 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)