@@ -10,16 +10,16 @@ API toolkit to access convex network.
1010First import the library and setup the convex API connection
1111
1212``` js
13- import { ConvexAPI , ConvexAccount } from ' @convex-dev/convex-api-js'
14-
15- const convex = new ConvexAPI (' https://convex.world' )
13+ import { API , Account , KeyPair } from ' @convex-dev/convex-api-js'
1614
15+ const convex = API .create (' https://convex.world' )
1716```
1817
19- Create a new account with random keys.
20- ``` js
18+ Create a new account with some a random key pair.
2119
22- const account = convex .createAccount ()
20+ ``` js
21+ const keyPair = KeyPair .create ()
22+ const account = convex .createAccount (keyPair)
2323```
2424
2525Topup account to have sufficient funds.
@@ -30,13 +30,15 @@ Topup account to have sufficient funds.
3030```
3131
3232Check the balance on the new account.
33+
3334``` js
3435 const balance = await convex .getBalance (account)
3536 console .log (` The account ${ account .address } has a balance of ${ balance} ` )
3637
3738```
3839
3940Do a send, this will cost the account a small fee so we need the account object to sign the transaction.
41+
4042``` js
4143 const resultSend = await convex .send (' (map inc [1 2 3 4 5])' , account)
4244 consol .log (` Result from calculation ${ resultSend} ` )
@@ -51,38 +53,40 @@ This can be usefull if you whish to query an actors state by using the actors ad
5153 consol .log (` Result from a query ${ resultQuery} ` )
5254```
5355
54- ## Example using an account with a name
56+ ## Example using an key pairs with an account name
5557
5658We have already saved an existing account keys in a .pem file
5759So first we need to import the account details public/private keys using it's encrypted data on file
5860
5961``` js
60- importAccount = ConvexAccount .importFromFile (' my-account.pem' , ' secret' )
61-
62+ importKeyPair = keyPair .importFromFile (' my-account.pem' , ' secret' )
6263```
6364
6465Create a new account address for the first time, or if the account name has already been regisetered
6566then load in the account address.
6667
6768The returned account object will have the account address assigned to the account name ` my-account ` .
69+
6870``` js
69- const account = await convex .setupAccount (' my-account' , importAccount )
71+ const account = await convex .setupAccount (' my-account' , importKeyPair )
7072```
7173
7274Later on you may need to re-load the same account address using only the registered name.
75+
7376``` js
74- const sameAccount = await convex .loadAccount (' my-account' , importAccount )
77+ const sameAccount = await convex .loadAccount (' my-account' , importKeyPair )
7578```
7679
7780You can still use ` setupAccount ` this will just call ` loadAccount ` if the account name is registered with the registry.
81+
7882``` js
7983 // or the same as
80- const sameAccount = await convex .setupAccount (' my-account' , importAccount )
84+ const sameAccount = await convex .setupAccount (' my-account' , importKeyPair )
8185```
8286
8387
8488If you just want to find out a name from the registry you can just do this:
89+
8590``` js
8691 const accountAddress = await convex .resolveAccountName (' my-account' )
87-
8892```
0 commit comments