-
Notifications
You must be signed in to change notification settings - Fork 211
/
queryTransaction.js
53 lines (43 loc) · 1.78 KB
/
queryTransaction.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
44
45
46
47
48
49
50
51
52
53
import { CodePromise, Abi, ContractPromise } from '@polkadot/api-contract';
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
import { BN, BN_ONE } from '@polkadot/util';
// import .contract file as json string
import { json } from "./abi.js"
const MAX_CALL_WEIGHT = new BN(500_000_000_000).isub(BN_ONE);
const PROOFSIZE = new BN(1_000_000);
try {
// API creation for connection to the chain
const wsProvider = new WsProvider('wss://wss-testnet.5ire.network/');
const api = await ApiPromise.create({ provider: wsProvider });
// gas limit for deployment
//const gasLimit = 100000n * 1000000n
const gasLimit = api.registry.createType('WeightV2', {
refTime: MAX_CALL_WEIGHT,
proofSize: PROOFSIZE,
});
// adding fire account for paying the gas fee
const PHRASE = 'negative cheap cherry uncover absurd angle swarm armor tuna lounge hurdle lawsuit';
const keyring = new Keyring({ type: "ed25519" });
const userKeyring = keyring.addFromMnemonic(PHRASE);
// parameters for constructor function inside the contract
// Put your contract address that you already deployed
const contract = new ContractPromise(api, json, '5DtUeGKHRjSpk79R5GuD6iuH67bZwkXXxRbtsWXgih2BvGG6');
// Query value from contract
const { result, output } = await contract.query.balanceOf(
userKeyring.address,
{
gasLimit: gasLimit,
storageDepositLimit: null,
}, '5GhS8ddBoA9pbUz1Z49Wh9Kx36MoHLZrVTNk2dj6R93hqd6m'
);
// check if the call was successful
if (result.isOk) {
// output the return value
console.log('Success -> Value:', output.toHuman());
} else {
console.error('Error', result.asErr);
}
}
catch (err) {
console.log("error", err.toString())
}