@@ -12,41 +12,43 @@ First you need to download the Convex-API-py package from the python package ind
12
12
13
13
You can now access the convex network, and get a balance from an existing account on the network by doing the following:
14
14
15
- >>> from convex_api import ConvexAPI
16
- >>> convex_api = ConvexAPI ('https://convex.world')
17
- >>> convex_api .get_balance(9)
15
+ >>> from convex_api import API
16
+ >>> convex = API ('https://convex.world')
17
+ >>> convex .get_balance(9)
18
18
99396961137042
19
19
20
20
You can create a new emtpy account, with now balance:
21
21
22
- >>> account = convex_api.create_account()
22
+ >>> key_pair = KeyPair.create()
23
+ >>> account = convex.create_account(key_pair)
23
24
>>> account.address
24
25
809
25
26
26
27
You can request some funds to the new account and then get the account information:
27
28
28
29
>>> convex_api.request_funds(1000000, account)
29
30
1000000
30
- >>> convex_api .get_account_info(account)
31
+ >>> convex .get_account_info(account)
31
32
{'environment': {}, 'address': 809, 'is_library': False, 'is_actor': False, 'memory_size': 42, 'balance': 1000000, 'allowance': 0, 'sequence': 0, 'type': 'user'}
32
33
33
34
34
35
You can export the accounts private key encoded as PKCS8 encrypt the key with a password:
35
36
36
- >>> account.export_to_text('secret')
37
+ >>> account.key_pair. export_to_text('secret')
37
38
'-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAiMY42UY4PXHAICCAAw\nDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEJpwDMicGbGj2iSJesktIVYEQBsp\nKMTAHzvUyw8jZRr8WSrmxH7938sjma8XWI6lgd9jwTZzcGamog7p3zatw0Wp+jFK\nKruWAZmIqhBZ/2ezDv8=\n-----END ENCRYPTED PRIVATE KEY-----\n'
38
39
39
40
>>> account.address
40
41
809
41
42
42
43
To re-use your account again you need to import the encrypted private key and set the correct account address
43
44
44
- >>> from convex_api import Account
45
- >>> account = Account.import_from_file('my_key.dat', 'secret', address=809)
45
+ >>> from api import Account, KeyPair
46
+ >>> key_pair = KeyPair.import_from_file('my_key.dat', 'secret')
47
+ >>> account = Account.create(key_pair, 809)
46
48
47
49
To create a new address with the same account keys in your new or imported account object, you can do:
48
50
49
- >>> new_account = convex_api .create_account(account )
51
+ >>> new_account = convex .create_account(key_pair )
50
52
>>> account.address
51
53
809
52
54
>>> new_account.address
@@ -55,37 +57,37 @@ To create a new address with the same account keys in your new or imported accou
55
57
To use account names, where an account name is resolved to a fixed address. You can create or load
56
58
an account based on it's name by doing the following:
57
59
58
- >>> account = convex_api .setup_account('my-account-name', import_account )
60
+ >>> account = convex .setup_account('my-account-name', key_pair )
59
61
>>> account.address
60
62
934
61
63
62
- >>> convex_api .resolve_account_name('my-account-name')
64
+ >>> convex .resolve_account_name('my-account-name')
63
65
934
64
66
65
- >>> same_account = convex_api .setup_account('my-account-name', import_account )
67
+ >>> same_account = convex .setup_account('my-account-name', key_pair )
66
68
>>> same_account.address
67
69
934
68
70
69
71
To submit a transaction, use ConvexAPI.send(). This will cost a small about of juice, and reduce your balance
70
72
71
- >>> convex_api .request_funds(1000000, account)
73
+ >>> convex .request_funds(1000000, account)
72
74
1000000
73
- >>> convex_api .send('(map inc [1 2 3 4])', account)
75
+ >>> convex .send('(map inc [1 2 3 4])', account)
74
76
{'value': [2, 3, 4, 5]}
75
- >>> convex_api .get_balance(account)
77
+ >>> convex .get_balance(account)
76
78
996360
77
79
78
80
To send a query a transaction, this is free and can be performed by any valid account address.
79
81
So for example to query a balance of an account:
80
82
81
- >>> convex_api .query(f'(balance {account.address})', account)
83
+ >>> convex .query(f'(balance {account.address})', account)
82
84
{'value': 996360}
83
85
84
86
# this is the same as above
85
- >>> convex_api .query(f'(balance {account.address})', account.address)
87
+ >>> convex .query(f'(balance {account.address})', account.address)
86
88
{'value': 996360}
87
89
88
90
# get the balance using one of the standard account addresses (#1)
89
- >>> convex_api .query(f'(balance {account.address})', 1)
91
+ >>> convex .query(f'(balance {account.address})', 1)
90
92
{'value': 996360}
91
93
0 commit comments