Skip to content

Commit 3aa76b9

Browse files
committed
fix: modify init params
1 parent ffe6161 commit 3aa76b9

File tree

7 files changed

+46
-14
lines changed

7 files changed

+46
-14
lines changed

examples/create_account.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const Ain = require('@ainblockchain/ain-js').default;
22

3-
const ain = new Ain('https://testnet-api.ainetwork.ai');
3+
const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);
4+
5+
// if you want to use mainnet, uncomment the following line:
6+
// const ain = new Ain('https://mainnet-api.ainetwork.ai', 'wss://mainnet-event.ainetwork.ai', 1);
47

58
function main() {
69
// create new account

examples/create_app.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
const Ain = require('@ainblockchain/ain-js').default;
2+
const { sleep } = require('./utils');
23

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);
48

59
async function main() {
610
// import the account using private key
711
const address = ain.wallet.addAndSetDefaultAccount('YOUR_PRIVATE_KEY');
812

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';
1017
const appPath = `/apps/${appName}`;
1118

1219
// create an app at /apps/${appName}
@@ -18,7 +25,7 @@ async function main() {
1825
},
1926
service: {
2027
staking: {
21-
lockup_duration: 604800000, // 7d in ms
28+
lockup_duration: 604800000, // 7d
2229
},
2330
},
2431
},
@@ -28,9 +35,11 @@ async function main() {
2835
});
2936

3037
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
3338
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
3443

3544
// get app owner at /apps/${appName}
3645
const owner = await ain.db.ref(appPath).getOwner();

examples/set_function.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const Ain = require('@ainblockchain/ain-js').default;
22

3-
const ain = new Ain('https://testnet-api.ainetwork.ai');
3+
const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);
4+
5+
// if you want to use mainnet, uncomment the following line:
6+
// const ain = new Ain('https://mainnet-api.ainetwork.ai', 'wss://mainnet-event.ainetwork.ai', 1);
47

58
async function main() {
69
// import the account using private key
@@ -26,9 +29,9 @@ async function main() {
2629
});
2730

2831
console.log('tx_hash:', res.tx_hash);
32+
console.log('code:', res.result.code);
2933
// 0: success, if not 0, check the error code:
3034
// https://github.com/ainblockchain/ain-blockchain/blob/master/common/result-code.js
31-
console.log('code:', res.result.code);
3235
}
3336

3437
main();

examples/set_rule.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const Ain = require('@ainblockchain/ain-js').default;
22

3-
const ain = new Ain('https://testnet-api.ainetwork.ai');
3+
const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);
4+
5+
// if you want to use mainnet, uncomment the following line:
6+
// const ain = new Ain('https://mainnet-api.ainetwork.ai', 'wss://mainnet-event.ainetwork.ai', 1);
47

58
async function main() {
69
// import the account using private key
@@ -22,9 +25,9 @@ async function main() {
2225
});
2326

2427
console.log('tx_hash:', res.tx_hash);
28+
console.log('code:', res.result.code);
2529
// 0: success, if not 0, check the error code:
2630
// https://github.com/ainblockchain/ain-blockchain/blob/master/common/result-code.js
27-
console.log('code:', res.result.code);
2831

2932
const rule = await ain.db.ref(appPath).getRule();
3033

examples/set_value.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const Ain = require('@ainblockchain/ain-js').default;
2+
const { sleep } = require('./utils');
23

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);
48

59
async function main() {
610
// import the account using private key
@@ -18,9 +22,11 @@ async function main() {
1822
});
1923

2024
console.log('tx_hash:', res.tx_hash);
25+
console.log('code:', res.result.code);
2126
// 0: success, if not 0, check the error code:
2227
// https://github.com/ainblockchain/ain-blockchain/blob/master/common/result-code.js
23-
console.log('code:', res.result.code);
28+
29+
await sleep(5000); // 5s
2430

2531
// check that the value is set correctly
2632
// if the echo bot is alive, it should have responded to your message

examples/stake_app.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const Ain = require('@ainblockchain/ain-js').default;
22

3-
const ain = new Ain('https://testnet-api.ainetwork.ai');
3+
const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);
4+
5+
// if you want to use mainnet, uncomment the following line:
6+
// const ain = new Ain('https://mainnet-api.ainetwork.ai', 'wss://mainnet-event.ainetwork.ai', 1);
47

58
async function main() {
69
// import the account using private key
@@ -20,9 +23,9 @@ async function main() {
2023
});
2124

2225
console.log('tx_hash:', res.tx_hash);
26+
console.log('code:', res.result.code);
2327
// 0: success, if not 0, check the error code:
2428
// https://github.com/ainblockchain/ain-blockchain/blob/master/common/result-code.js
25-
console.log('code:', res.result.code);
2629
}
2730

2831
main();

examples/utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2+
3+
module.exports = {
4+
sleep,
5+
};

0 commit comments

Comments
 (0)