0

=====USING===

Sepolia Testnet, metamask, web3js and walletConnectModel

=====ERROR===

sendSignedTransaction error: ResponseError: Returned error: err: insufficient funds for gas * price + value: address 0x7C591eCE68c3Bbb95f6fbdDb8D1c5e4F2515eE49 have 0 want 29946172782604096 (supplied gas 300000)

=====CODE====

    async function invoke() {
      const web3 = new Web3(walletProvider);
      const nonce = await web3.eth.getTransactionCount(address, "pending", { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX });
      const gasPrice = await web3.eth.getGasPrice({ number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX });
      const gasLimit = web3.utils.toHex(300000n);

      const transactionObj = {
        nonce,
        chainId,
        gasPrice,
        gasLimit,
        from: address,
        to: store.address,
        value: "0x1000",
        data: "0x",
        v: "0x7926",
        r: "0x",
        s: "0x",
      };

      const transactionTxi = new ethereumjs.Tx(transactionObj);
      const transactionHex = "0x" + transactionTxi.serialize().toString("hex");
      const transactionRaw = web3.utils.sha3(transactionHex, {encoding: "hex"});

      await web3.eth
        .sign(transactionRaw, address)
        .then(async (hash) => {
          const firstPrefix = hash.substring(2);
          const r = "0x" + firstPrefix.substring(0, 64);
          const s = "0x" + firstPrefix.substring(64, 128);
          const fullHash = parseInt(firstPrefix.substring(128, 130), 16);
          const v = web3.utils.toHex(fullHash + chainId * 2 + 8);

          transactionTxi.r = r;
          transactionTxi.s = s;
          transactionTxi.v = v;

          const signedTxi = "0x" + transactionTxi.serialize().toString("hex");

          await new Promise(async (resolve, reject) => {
            await web3.eth
              .sendSignedTransaction(signedTxi)
              .once("transactionHash", (hash) => {
                console.log("done", hash);
                resolve(hash);
              })
              .catch((error) => {
                reject(error);
              });
          })
            .then(async (hash) => {
              console.log("complete");
            })
            .catch((error) => {
              console.log("sendSignedTransaction error:", error);
            });
        })
        .catch((error) => {
          console.log("sign error:", error);
        });
    }
4
  • The error is simple, fund your wallet before sending any transaction. Commented Jan 18 at 11:23
  • already funded with 0.7 SepoliaETH
    – Rommer
    Commented Jan 18 at 12:30
  • Doesn't seem like the address provided in the error message has any funds. Commented Jan 18 at 16:48
  • address provided in error message is dynamic. its neither from and nor to address
    – Rommer
    Commented Jan 18 at 17:21

0

Your Answer

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