The Problem
I recently switched from polkadot-v0.20.0 to polkadot-v0.37.0 in order to support V4 Ink Smart contracts.
But I am encountering the following error using the npm package @polkadot/api when batching multiple transactions as such:
await Promise.all(
txs[addressid].map(async (val) => {
let tokenId = Math.floor(100000 * Math.random());
while (tokenIds.includes(tokenId)) {
tokenId = Math.floor(100000 * Math.random());
}
const storageDepositLimit = null;
const { gasRequired } = await contract.query.mint(
"",
{
gasLimit: api?.registry.createType("WeightV2", {
refTime: MAX_CALL_WEIGHT,
proofSize: PROOFSIZE,
}),
storageDepositLimit,
},
tokenId,
val.name,
parseInt(val.price)
);
const gasLimit = api?.registry.createType("WeightV2", gasRequired)
out.push(
contract.tx.mint(
{ gasLimit },
tokenId,
val.name,
parseInt(val.price)
)
);
val.tokenId = tokenId;
checks.push(val);
})
);
await new Promise((resolve) => {
api.tx.utility.batch(out).signAndSend(wallet, ({ status }) => {
if (status.isInBlock) {
////console.log`Completed at block hash #${status.asInBlock}`);
resolve();
}
});
});
RPC-CORE: call(method: Text, data: Bytes, at?: BlockHash): Bytes:: -32000: Client error: Execution failed: failed to instantiate a new WASM module instance: Limit of 32 concurrent instances has been reached".
On my substrate node, I had this error as well:
Ran out of free WASM instances
But I was able to solve this error by using the following flag:
--max-runtime-instance 256
Although the 'Ran out of free Wasm instances' error went away, i still have the Limit of 32 concurrent instances reached error!
my node is running polkadot-v0.37.0 npm packages:
"@polkadot/api": "9.10.5",
"@polkadot/api-contract": "9.10.5",
My suspicion
I think this has something to do with the fact that I transitioned from BTreeMap to a Mapping as a way to store values because BTreeMap is limited in how many keys it can store