@@ -12,41 +12,43 @@ First you need to download the Convex-API-py package from the python package ind
1212
1313You can now access the convex network, and get a balance from an existing account on the network by doing the following:
1414
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)
1818 99396961137042
1919
2020You can create a new emtpy account, with now balance:
2121
22- >>> account = convex_api.create_account()
22+ >>> key_pair = KeyPair.create()
23+ >>> account = convex.create_account(key_pair)
2324 >>> account.address
2425 809
2526
2627You can request some funds to the new account and then get the account information:
2728
2829 >>> convex_api.request_funds(1000000, account)
2930 1000000
30- >>> convex_api .get_account_info(account)
31+ >>> convex .get_account_info(account)
3132 {'environment': {}, 'address': 809, 'is_library': False, 'is_actor': False, 'memory_size': 42, 'balance': 1000000, 'allowance': 0, 'sequence': 0, 'type': 'user'}
3233
3334
3435You can export the accounts private key encoded as PKCS8 encrypt the key with a password:
3536
36- >>> account.export_to_text('secret')
37+ >>> account.key_pair. export_to_text('secret')
3738 '-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAiMY42UY4PXHAICCAAw\nDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEJpwDMicGbGj2iSJesktIVYEQBsp\nKMTAHzvUyw8jZRr8WSrmxH7938sjma8XWI6lgd9jwTZzcGamog7p3zatw0Wp+jFK\nKruWAZmIqhBZ/2ezDv8=\n-----END ENCRYPTED PRIVATE KEY-----\n'
3839
3940 >>> account.address
4041 809
4142
4243To re-use your account again you need to import the encrypted private key and set the correct account address
4344
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)
4648
4749To create a new address with the same account keys in your new or imported account object, you can do:
4850
49- >>> new_account = convex_api .create_account(account )
51+ >>> new_account = convex .create_account(key_pair )
5052 >>> account.address
5153 809
5254 >>> new_account.address
@@ -55,37 +57,37 @@ To create a new address with the same account keys in your new or imported accou
5557To use account names, where an account name is resolved to a fixed address. You can create or load
5658an account based on it's name by doing the following:
5759
58- >>> account = convex_api .setup_account('my-account-name', import_account )
60+ >>> account = convex .setup_account('my-account-name', key_pair )
5961 >>> account.address
6062 934
6163
62- >>> convex_api .resolve_account_name('my-account-name')
64+ >>> convex .resolve_account_name('my-account-name')
6365 934
6466
65- >>> same_account = convex_api .setup_account('my-account-name', import_account )
67+ >>> same_account = convex .setup_account('my-account-name', key_pair )
6668 >>> same_account.address
6769 934
6870
6971To submit a transaction, use ConvexAPI.send(). This will cost a small about of juice, and reduce your balance
7072
71- >>> convex_api .request_funds(1000000, account)
73+ >>> convex .request_funds(1000000, account)
7274 1000000
73- >>> convex_api .send('(map inc [1 2 3 4])', account)
75+ >>> convex .send('(map inc [1 2 3 4])', account)
7476 {'value': [2, 3, 4, 5]}
75- >>> convex_api .get_balance(account)
77+ >>> convex .get_balance(account)
7678 996360
7779
7880To send a query a transaction, this is free and can be performed by any valid account address.
7981So for example to query a balance of an account:
8082
81- >>> convex_api .query(f'(balance {account.address})', account)
83+ >>> convex .query(f'(balance {account.address})', account)
8284 {'value': 996360}
8385
8486 # 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)
8688 {'value': 996360}
8789
8890 # 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)
9092 {'value': 996360}
9193
0 commit comments