1
1
const Ain = require ( '@ainblockchain/ain-js' ) . default ;
2
+ const { sleep } = require ( './utils' ) ;
2
3
3
- const ain = new Ain ( 'https://testnet-api.ainetwork.ai' ) ;
4
+ const ain = new Ain ( 'https://testnet-api.ainetwork.ai' , 'wss://testnet-event.ainetwork.ai' , 0 ) ;
5
+
6
+ // if you want to use mainnet, uncomment the following line:
7
+ // const ain = new Ain('https://mainnet-api.ainetwork.ai', 'wss://mainnet-event.ainetwork.ai', 1);
4
8
5
9
async function main ( ) {
6
10
// import the account using private key
7
11
const address = ain . wallet . addAndSetDefaultAccount ( 'YOUR_PRIVATE_KEY' ) ;
8
12
9
- const appName = 'YOUR_APP_NAME' ; // define a unique app name (rename if write rule error occurs)
13
+ // define a unique app name
14
+ // the app name can only contain letters, numbers, and underscores(_)
15
+ // rename if write rule error occurs
16
+ const appName = 'YOUR_APP_NAME' ;
10
17
const appPath = `/apps/${ appName } ` ;
11
18
12
19
// create an app at /apps/${appName}
@@ -18,7 +25,7 @@ async function main() {
18
25
} ,
19
26
service : {
20
27
staking : {
21
- lockup_duration : 604800000 , // 7d in ms
28
+ lockup_duration : 604800000 , // 7d
22
29
} ,
23
30
} ,
24
31
} ,
@@ -28,9 +35,11 @@ async function main() {
28
35
} ) ;
29
36
30
37
console . log ( 'tx_hash:' , res . tx_hash ) ;
31
- // 0: success, if not 0, check the error code:
32
- // https://github.com/ainblockchain/ain-blockchain/blob/master/common/result-code.js
33
38
console . log ( 'code:' , res . result . code ) ;
39
+ // 0: success, if not 0, check the error code:
40
+ // https://github.com/ainblockchain/ain-blockchain/blob/master/common/result-code.js
41
+
42
+ await sleep ( 5000 ) ; // 5s
34
43
35
44
// get app owner at /apps/${appName}
36
45
const owner = await ain . db . ref ( appPath ) . getOwner ( ) ;
0 commit comments