I'm trying to read the flipper contract data from a contract in a local node, following the code in here. This is my code:
// Required imports
const { ApiPromise, WsProvider } = require("@polkadot/api");
const { ContractPromise } = require("@polkadot/api-contract");
const { keyring } = require("@polkadot/ui-keyring");
keyring.loadAll({ ss58Format: 42, type: "sr25519" });
const abi = require("./metadata.json");
async function main() {
const provider = new WsProvider("ws://127.0.0.1:9944");
const api = await ApiPromise.create({ provider });
const contractAddress = "5HDxbYh52Wb34ATHwWhct1FQ4gnavcK8kAyMAVRdHUxgDhYo";
const contract = new ContractPromise(api, abi, contractAddress);
const alicePair = keyring.createFromUri("//Alice");
const value = 0;
const gasLimit = 3000n * 1000000n;
const { gasConsumed, result, output } = await contract.query.get(
alicePair.address,
{ value, gasLimit }
);
console.log(result.toHuman());
console.log(gasConsumed.toHuman());
if (result.isOk) {
console.log("Success", output.toHuman());
} else {
console.error("Error", result.asErr);
}
}
main()
.catch(console.error)
.finally(() => process.exit());
After running this file with node, this is the output:
{ Err: { Module: { index: '8', error: '1', message: 'OutOfGas' } } }
3,000,000,000
Error Type {
registry: TypeRegistry { createdAtHash: undefined },
createdAtHash: undefined,
initialU8aLength: undefined,
isOther: [Getter],
isCannotLookup: [Getter],
isBadOrigin: [Getter],
isModule: [Getter],
asOther: [Getter],
asCannotLookup: [Getter],
asBadOrigin: [Getter],
asModule: [Getter]
}
What caused the error and how to fix it?