Cant deploy my contract

I am trying to deploy my contract on sepolia test network , and I am getting same error for couple of days .

Error: The contract code couldn't be stored, please check your gas limit.

I have 2 test eth on my network . I have tried different gas limit for my contract . I tried to optimize my contract (but it is too small to optimize ).Dont know where I am missing the spot .
here is the deploy.js file

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

const Web3 = require('web3');

const { interface, bytecode } = require('./compile');

const provider = new HDWalletProvider(
//I put my account phrase here .
   'https://sepolia.infura.io/v3/9d4945325d2c4515a117aaafa6b5af54'
);

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))
        .deploy({ data: '0x0' + bytecode, arguments: ['Hi there'] })
        .send({ gas: "30000000",from: accounts[0] });

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

};
deploy();

my main contract

pragma solidity >=0.4.26;

contract Inbox {
    string public message="hello";
  

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

Here is 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']);

I'm far from comfortable with web3.eth.Contract but are you certain your data requires a leading zero following the 0x? That seems like it would change things post-compile if the bytecode length is even.

can you use remix to deploy your contract. makes the process simpler and faster.

https://remix.ethereum.org/

I am new to solidity. I did try this solution from resources I found on internet . To put "0x0" to solve my error . Even though I remove it ,it still shows the same error .Thanks a lot .

I wanted to deploy this contract from VS code . I am learning from scratch.Thanks for reaching me out .

1 Like

use remix.

I think it is better and easier to deploy

I've recreated your file system and got this working. The only time I could reproduce your error is when I didn't have any ETH. Goerli has a trickling faucet, perhaps you could try there? Simply switch your provider:

const provider = new HDWalletProvider({
    privateKeys: ["0xaabbcc"], // your PrivKey goes here, switch back to mnemonic if preferred
    providerOrUrl: 'https://goerli.infura.io/v3/9d4945325d2c4515a117aaafa6b5af54'
});

Note: FYI I did add the curly-braces as they were missing in your post, in case that was the issue

I did same as yours , there are so many garbage values on the terminal and at the end it says , type error

e.includes is not a function

which line of which file is throwing that error?

1 Like

After replacing that portion of the code
I tried to run my deploy.js file by the command

node deploy.js
then there's a tons of garbage values and at the end it say that error I already mention above

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

const Web3 = require('web3');

const { interface, bytecode } = require('./compile');

const provider = new HDWalletProvider({
//    'rotate private anger humor social predict title pear number firm mercy reopen', 
//     'https://goerli.infura.io/v3/9d4945325d2c4515a117aaafa6b5af54'
    privateKeys: [""], // my account private key is here 
    providerOrUrl: 'https://goerli.infura.io/v3/9d4945325d2c4515a117aaafa6b5af54'

});

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))
        .deploy({ data:  bytecode, arguments: ['Hi there'] })
        .send({ gas: "10000000",from: accounts[0] });

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

};
deploy();

here it is

The error says something like this

TypeError: e.includes is not a function
at G:\Course\inbox\inbox\node_modules\truffle-hdwallet-provider\dist\index.js:15:4083
at new b (G:\Course\inbox\inbox\node_modules\truffle-hdwallet-provider\dist\index.js:15:4103)
at Object. (G:\Course\inbox\inbox\deploy.js:7:18)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47

I'm afraid you might be using a mnemonic rather than privateKeys, change that attribute to "mnemonic" if you are.

@truffle/hdwallet-provider - npm (npmjs.com)

Sidenote: I also noticed a few punctuation anomalies in the original post's provider variable. If THAT was the original problem you may encounter an issue of not having goerli ETH where then switching back to sepolia would achieve results.

1 Like

Thank you so much for your constant support. I successfully able to deploy my first smart contract .You were kind to me ,I have been struggling with this probelm for few days .I appreciate your constant supprt .<3

1 Like

I'm sincerely happy to help! Keep up the good fight