1

I'm trying to call a message on my ink! v3 smart contract using the polkadot-js ContractPromise but I'm getting the error:

system.ExtrinsicFailed::ExtrinsicFailed:: contracts.OutOfGas

This is how I'm making the call:


  const eventList: EventList[] = [];
  const pr = new Promise((res, rej) => {
    // Dry run the call
    contract.query
      .initiateVerficationFlow(address, {})
      .then((value) => {
        // create weightV2 type by calling registry.createType, similar to https://github.com/paritytech/contracts-ui/blob/master/src/helpers/callOptions.ts#L42
        const gasLimit = getGasLimit(
          value.gasRequired.refTime.toBn(),
          value.gasRequired.proofSize.toBn(),
          contract.registry
        );

        // Make the call, and listen to events
        contract.tx
          .initiateVerficationFlow({
            storageDepositLimit: value.storageDeposit.asCharge,
            gasLimit: gasLimit,
            value: 100n,
          })
          .signAndSend(
            address,
            signer,
            handleEvents(contract.api as ApiPromise, [0, eventList], res, rej)
          );
      })
      .catch(rej);
  });

  const response = await pr;
  console.log(response);

I noticed that this call resolves successfully with the polkadot-js web app from ink-waterfall: https://polkadotjs-apps.web.app/ , and the contracts-ui https://contracts-ui.substrate.io/contract .

Is there something I'm missing?

1

2 Answers 2

2

Yes, WeightsV2 is the issue. You can do it the "low level" way with PolkadotJS that involves encoding / decoding the data, or if you are using React you can use useink beta useContractTx hook.

  1. Here is what it does under the hood if you are not using React.
  2. With React:
const contract = useContract(...yourArgs)
const tx = useContactTx(contract, 'myMessageName');
const txArgs = ['Squink', 1000];

return (
  <div>
    <button onClick(() => tx.send(txArgs)>Submit</button
    Status: {tx.status}
  </div>
)

useink is beta now and has come big changes coming up, but it will do all of the nasty decoding work and handle WeightsV2 under the hood for you.

There are more hooks in there you may find useful. E.g. useContractCall, which will read from the contract on each new block.

1

The polkadot-js UI unfortunately doesn't support Weights V2 yet.

You are better off using https://contracts-ui.substrate.io/ for now.

Your Answer

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

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