Search code examples
javascriptsolidityweb3js

transaction underpriced error occured whever i tried to run the below code


const tx = {
    nonce: 5,
    gasPrice: 20000000000,
    gasLimit: 1000000,
    to: null,
    value: 0,
    data: "0x608060405234801561001057600",
    chainId: 1337,
  };
  // const signedTxResponse = await wallet.signTransaction(tx);
  const sentTxResponse = await wallet.sendTransaction(tx);
  // await sentTxResponse.wait(1);
  console.log("sentTxResponse", sentTxResponse);

i have an error for the above code its give me an transaction underpriced error error: could not coalesce error

(error={ "code": -32003, "message": "transaction underpriced", "stack": "Error: transaction underpriced\\n    at shouldReplace (/tmp/.mount_ganach8fQ6uV/resources/static/node/node_modules/ganache/dist/node/1.js:2:119740)\\n    at TransactionPool.prepareTransaction (/tmp/.mount_ganach8fQ6uV/resources/static/node/node_modules/ganache/dist/node/1.js:2:122311)" }, code=UNKNOWN_ERROR, version=6.4.0)  

i tried to change the gas limit and gas price


Solution

  •     const nonce = await wallet.getNonce()
        const tx = {
            nonce: nonce,
            gasPrice: 20000000000,
            gasLimit: 1000000,
            to: null,
            value: 0,
            data: "0x608060405234801561001057600",
            chainId: 1337,
          };
       // const signedTxResponse = await wallet.signTransaction(tx);
       const sentTxResponse = await wallet.sendTransaction(tx);
       // await sentTxResponse.wait(1);
       console.log("sentTxResponse", sentTxResponse);