-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_rule.js
43 lines (34 loc) · 1.17 KB
/
set_rule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const Ain = require('@ainblockchain/ain-js').default;
const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);
// if you want to use mainnet, uncomment the following line:
// const ain = new Ain('https://mainnet-api.ainetwork.ai', 'wss://mainnet-event.ainetwork.ai', 1);
async function main() {
// import the account using private key
const address = ain.wallet.addAndSetDefaultAccount('YOUR_PRIVATE_KEY');
const appName = 'YOUR_APP_NAME'; // use your app name
const appPath = `/apps/${appName}`;
// set write rules to allow anyone to write data
const res = await ain.db.ref(appPath).setRule({
value: {
'.rule': {
write: true,
},
},
gas_price: 500,
timestamp: Date.now(),
nonce: -1,
});
console.log('tx_hash:', res.tx_hash);
console.log('code:', res.result.code);
// 0: success, if not 0, check the error code:
// https://github.com/ainblockchain/ain-blockchain/blob/master/common/result-code.js
const rule = await ain.db.ref(appPath).getRule();
console.log(JSON.stringify(rule, null, 2));
// example output:
// {
// ".rule": {
// "write": true
// }
// }
}
main();