1

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());
3
  • 2
    Can you provide the configuration of your runtime, about the parameter following: pub RuntimeBlockLength: BlockLength = BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); Feb 28, 2022 at 5:00
  • @ironman_ch_parami, it's the default configuration of substrate
    – Minh Mốc
    Feb 28, 2022 at 6:49
  • @ironman_ch_parami I tried with the flipper contract but the error is still there
    – Minh Mốc
    Mar 1, 2022 at 2:35

2 Answers 2

1

I found the solution, I set the gas limit too high. Thank you all for your support!

0
0

I solved it by going to contracts-UI. Then pretending to want to call the function with the parameters. Automatically the real values (max and to-be-used) are computed by the UI. You can just copy it into your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.