import { BN, BN_ONE } from "@polkadot/util";
import type { WeightV2 } from '@polkadot/types/interfaces'
import { BN, BN_ONE } from "@polkadot/util";
import type { WeightV2 } from '@polkadot/types/interfaces'
const MAX_CALL_WEIGHT = new BN(5_000_000_000_000).isub(BN_ONE);
const PROOFSIZE = new BN(1_000_000);
const MAX_CALL_WEIGHT = new BN(5_000_000_000_000).isub(BN_ONE);
const PROOFSIZE = new BN(1_000_000);
const storageDepositLimit = null;
const { gasRequired } = await contract.query.flip(
account.address,
{
gasLimit: api?.registry.createType('WeightV2', {
refTime: MAX_CALL_WEIGHT,
proofSize: PROOFSIZE,
}) as WeightV2,
storageDepositLimit,
}
);
const storageDepositLimit = null;
const { gasRequired } = await contract.query.flip(
account.address,
{
gasLimit: api?.registry.createType('WeightV2', {
refTime: MAX_CALL_WEIGHT,
proofSize: PROOFSIZE,
}) as WeightV2,
storageDepositLimit,
}
);
const gasLimit = api?.registry.createType('WeightV2', gasRequired) as WeightV2
await contract.tx
.flip({
gasLimit,
storageDepositLimit
})
.signAndSend(alice, async (res) => {
if (res.status.isInBlock) {
console.log('in a block')
} else if (res.status.isFinalized) {
console.log('finalized')
}
});
const gasLimit = api?.registry.createType('WeightV2', gasRequired) as WeightV2
await contract.tx
.flip({
gasLimit,
storageDepositLimit
})
.signAndSend(alice, async (res) => {
if (res.status.isInBlock) {
console.log('in a block')
} else if (res.status.isFinalized) {
console.log('finalized')
}
});
const { result, output } = await contract.query.get(
alice.address,
{
gasLimit: api?.registry.createType('WeightV2', {
refTime: MAX_CALL_WEIGHT,
proofSize: PROOFSIZE,
}) as WeightV2,
storageDepositLimit,
}
);
// The actual result from RPC as `ContractExecResult`
console.log(result.toHuman());
// check if the call was successful
if (result.isOk) {
// output the return value
console.log("Success", output?.toHuman());
} else {
console.error("Error", result.asErr);
}
const { result, output } = await contract.query.get(
alice.address,
{
gasLimit: api?.registry.createType('WeightV2', {
refTime: MAX_CALL_WEIGHT,
proofSize: PROOFSIZE,
}) as WeightV2,
storageDepositLimit,
}
);
// The actual result from RPC as `ContractExecResult`
console.log(result.toHuman());
// check if the call was successful
if (result.isOk) {
// output the return value
console.log("Success", output?.toHuman());
} else {
console.error("Error", result.asErr);
}