I am new to solidity . I am trying to learn solidity following a course . I trying to deploy my contract . I am getting same error again and again . I have tried some solution with same title I found here . It seems not work .

The error says :

Error: insufficient funds for gas * price + value

I am stuck with this error for so long .

My sepolia test network balance is 0.0022 ,do I have to get more ?

here is deploy.js file

const HDWalletProvider=require('truffle-hdwallet-provider');

const Web3=require('web3');


const provider=new HDWalletProvider(
    //i put my account prase here

const web3 =new Web3(provider);

const deploy= async()=>{

    const accounts=await web3.eth.getAccounts(); 

    console.log('Attempting to deploy from account',accounts[0]);

   const result= await new web3.eth.Contract(JSON.parse(interface))

    console.log('Contract deployed to',result.options.address);


my main contract :

pragma solidity >=0.4.26;

contract Inbox {
    string public message;

    constructor(string memory intialmsg) public{
        message = intialmsg;

    function setmessage(string memory newMessage) public {
        message = newMessage;

My compile.js file

const path= require('path');
const fs= require('fs');

const solc=require('solc');

const inboxPath=path.resolve(__dirname,'contracts','Inbox.sol');

const source = fs.readFileSync(inboxPath,'utf-8');

module.exports = solc.compile(source,1).contracts[':Inbox'];
console.log( solc.compile(source,1).contracts[':Inbox']);

My package.js file

  "name": "inbox",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha"
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ganache-cli": "^6.12.2",
    "mocha": "^10.2.0",
    "openzeppelin-solidity": "^4.6.0",
    "solc": "^0.4.26",
    "truffle-hdwallet-provider": "^1.0.17",
    "web3": "^1.0.0-beta.26"

Thanks a lot .Dont want to give up on my journey .


3 Answers 3


I also think that you don't have enough money for gas. You can use Remix Ide -> import your contract and inject Metamask and click to deploy to see how much a contract will cost to deploy.

  • I have 2eth now in my test network , the error says Error: The contract code couldn't be stored, please check your gas limit.
    – Shorna
    Commented Jan 14, 2023 at 17:47
  • try to increase gas from here : .send({gas:"1000000",from:accounts[0]});
    – Catalin
    Commented Jan 14, 2023 at 17:51
  • !!! You also posted your seed phrase. Everyone now have access to your fund. You should never post seed phrases, not even from testnets. Move your funds to another wallet
    – Catalin
    Commented Jan 14, 2023 at 17:52
  • i tried to increase gas from here ,i put different values ,it seems not to work
    – Shorna
    Commented Jan 14, 2023 at 17:56
  • try this stackoverflow.com/questions/70664908/…
    – Catalin
    Commented Jan 14, 2023 at 18:01

Using string in a constructor needs more gas than usual, also you set gas in your arguments , remove gas and try again , if it doesn't work set gas limit and gas price in arguments

  • .send({ gas: "10000000",gasLimit:"2000000",gasPrice:"2000", from: accounts[0] }); i tried tthis ,still getting the same error
    – Shorna
    Commented Jan 14, 2023 at 18:12

I could easily migrate with minimal settings in my ganache

enter image description here

enter image description here


const Inbox = artifacts.require("Inbox");

module.exports = function (deployer, network, accounts) {
  deployer.deploy(Inbox, "Hello World");


const HDWalletProvider = require('@truffle/hdwallet-provider');

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  contracts_build_directory: "./build/contracts",
  networks: {
    ropsten: {
      provider: () => new HDWalletProvider(mnemonic, ``),
      network_id: 5777,       // Ropsten's id
      gas: 5500000,        // Ropsten has a lower block limit than mainnet
      confirmations: 0,    // # of confirmations to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )

  // Set default mocha options here, use special reporters, etc.
  mocha: {
    // timeout: 100000

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.7",      // Fetch exact version from solc-bin (default: truffle's version)
      docker: false,        // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: false,
         runs: 200
       evmVersion: "byzantium"

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.