I'm trying to call a smart contract using the Polkadot JS API (like here). The contract function is really simple, it takes 2 strings: a key and a value as input parameters, then adds the key, value to a hashmap in the contract storage. I can call it normally in the PolkadotJs UI, but when try using the PolkadotJs Javascript API I got this error message:
2022-02-28 00:12:01 DRR: 1010: Invalid Transaction: Transaction would exhaust the block limits
Error: 1010: Invalid Transaction: Transaction would exhaust the block limits
at RpcCoder._checkError (/home/minhnd/node_modules/@polkadot/rpc-provider/coder/index.cjs:84:13)
at RpcCoder.decodeResponse (/home/minhnd/node_modules/@polkadot/rpc-provider/coder/index.cjs:47:10)
at WsProvider.value (/home/minhnd/node_modules/@polkadot/rpc-provider/ws/index.cjs:267:90)
at W3CWebSocket.value [as onmessage] (/home/minhnd/node_modules/@polkadot/rpc-provider/ws/index.cjs:247:153)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/minhnd/node_modules/yaeti/lib/EventTarget.js:107:17)
at W3CWebSocket.onMessage (/home/minhnd/node_modules/websocket/lib/W3CWebSocket.js:234:14)
at WebSocketConnection.<anonymous> (/home/minhnd/node_modules/websocket/lib/W3CWebSocket.js:205:19)
at WebSocketConnection.emit (node:events:520:28)
at WebSocketConnection.processFrame (/home/minhnd/node_modules/websocket/lib/WebSocketConnection.js:554:26)
at /home/minhnd/node_modules/websocket/lib/WebSocketConnection.js:323:40
2022-02-28 00:12:01 RPC-CORE: submitAndWatchExtrinsic(extrinsic: Extrinsic): ExtrinsicStatus:: 1010: Invalid Transaction: Transaction would exhaust the block limits
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("./freshdi_metadata.json");
async function main() {
const provider = new WsProvider("ws://127.0.0.1:9944");
const api = await ApiPromise.create({ provider });
const contractAddress = "5CbqJvv4VXFNsoK6nj95jD3ajopgJmrB5XP2vXHCvMekxqC6";
const contract = new ContractPromise(api, abi, contractAddress);
const alicePair = keyring.createFromUri("//Alice");
const value = 0;
const gasLimit = 5 * 1000000000000;
await contract.tx
.insertAction({ value, gasLimit }, "key_str","value_str")
.signAndSend(alicePair, (result) => {
if (result.status.isInBlock) {
console.log("in a block");
} else if (result.status.isFinalized) {
console.log("finalized");
}
});
}
main()
.catch(console.error)
.finally(() => process.exit());
pub RuntimeBlockLength: BlockLength = BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);