Need help, trying to deploy. Gas estimation failed (Remix)

Hi guys,

I am scratching my head here on what to do. Im not the best developer but I know a bit.

Im trying to deploy my contract on BSC Testnet (before I do Mainnet). But I get "gas estimation failed" as an error message in Remix.

I have set the optimization to 200. Environment is Injected Web3. Tried with different gas limits, have raised it high. Then the deployment (transaction) is just pending in Metamask and the contract never gets deployed.

This is the error message:
"Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }"

This is the contract Im trying to deploy:
https://github.com/shidoinu/SmartContract/blob/main/ShidoInuSmartContract.sol

What should I do? Is there some way to deploy this contract?

Please if someone can have a look. Maybe the contract is too big.

Thanks in advance.

Best regards,
Bjorn

Hi Bjorn,

I forked the github repo you stated above. Keep in mind I tried compiling this in Truffle through the Ropsten Ethereum Testnet.

The code compiled successfully but with a warning. Here is the output from my terminal:

newuser@admins-MacBook-Pro shidoinu % truffle compile -all

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/shidoinu.sol
> Compilation warnings encountered:

    project:/contracts/shidoinu.sol:350:1: Warning: Contract code size exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
contract ShidoInu is Context, IERC20, Ownable {
^ (Relevant source part starts here and spans across multiple lines).

> Artifacts written to /Users/newuser/shidoinu/build/contracts
> Compiled successfully using:
   - solc: 0.6.12+commit.27d51765.Emscripten.clang

Maybe this warning could give you more insight.

Next, I deployed the contract. Here is the response from my terminal:

newuser@admins-MacBook-Pro shidoinu % truffle deploy --network ropsten

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'ropsten'
> Network id:      3
> Block gas limit: 8000000 (0x7a1200)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0x94d5ecc44e9b8343b248f1e9d5d248193d4013418f85de791fdec81cbf5a7210
   > Blocks: 0            Seconds: 12
   > contract address:    0x5BbdA554Df10e73C7B9998031627623Fd70FAb11
   > block number:        12004672
   > block timestamp:     1645567622
   > account:             0x17169840959163e3515ff010C30235e011FcF300
   > balance:             0.995755310877280454
   > gas used:            188263 (0x2df67)
   > gas price:           2.501100039 gwei
   > value sent:          0 ETH
   > total cost:          0.000470864596642257 ETH

   Pausing for 2 confirmations...
   ------------------------------
   > confirmation number: 1 (block: 12004673)
   > confirmation number: 2 (block: 12004674)

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:     0.000470864596642257 ETH


2_deploy_contracts.js
=====================

   Deploying 'ShidoInu'
   --------------------
   > transaction hash:    0xd3b64d3b55787c0bfa0d7c486f4fc86f6ab65a83dea689490787f558c542b79d

Error:  *** Deployment Failed ***

"ShidoInu" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

It seems as if this contract has revert statements that are not playing nicely at the moment from my understanding. I could be wrong but this is my guess.

Hope this helps you out. As you see, I couldn't deploy the contract either but maybe I was using the wrong network, which is also a possibility. I really don't use Binance for my own personal reasons but I'll switch networks and try again for you.

Pavon

1 Like

OK so I added Binance Mainnet and Binance Testnet to my Metamask.

I also tapped into the testnet faucet to get some testnet BSC to try this out for you.

I modified my truffle-config.js file to include the BSC mainnet and testnet parameters as seen below:

/**
 * Use this file to configure your truffle project. It's seeded with some
 * common settings for different networks and features like migrations,
 * compilation and testing. Uncomment the ones you need or modify
 * them to suit your project as necessary.
 *
 * More information about configuration can be found at:
 *
 * trufflesuite.com/docs/advanced/configuration
 *
 * To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
 * to sign your transactions before they're sent to a remote public node. Infura accounts
 * are available for free at: infura.io/register.
 *
 * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
 * public/private key pairs. If you're publishing your code to GitHub make sure you load this
 * phrase from a file you've .gitignored so it doesn't accidentally become public.
 *
 */

const HDWalletProvider = require('@truffle/hdwallet-provider');
const { projectId, mnemonic } = require('./secrets.json');
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  /**
   * Networks define how you connect to your ethereum client and let you set the
   * defaults web3 uses to send transactions. If you don't specify one truffle
   * will spin up a development blockchain for you on port 9545 when you
   * run `develop` or `test`. You can ask a truffle command to use a specific
   * network from the command line, e.g
   *
   * $ truffle test --network <network-name>
   */

  networks: {
    // Useful for testing. The `development` name is special - truffle uses it by default
    // if it's defined here and no other network is specified at the command line.
    // You should run a client (like ganache-cli, geth or parity) in a separate terminal
    // tab if you use this network and you must also set the `host`, `port` and `network_id`
    // options below to some value.
    //
     development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
     },
     testnet: {
      provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-s1.binance.org:8545`),
      network_id: 97,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
    bsc: {
      provider: () => new HDWalletProvider(mnemonic, `https://bsc-dataseed1.binance.org`),
      network_id: 56,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
    // Another network with more advanced options...

Tried compiling the contract and was successful. When I deployed the contract to Binance Testnet, I was met with the same error (see below):

newuser@admins-MacBook-Pro shidoinu % truffle migrate --network testnet

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'testnet'
> Network id:      97
> Block gas limit: 30000000 (0x1c9c380)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xca21755da2507d903c8a32a754beabeb1fef1d6ca36d2a6fc73be66c5ecc98f0
   > Blocks: 3            Seconds: 9
   > contract address:    0x8D4a417B82348aD3B13dd88fddb29E6c7455c8AC
   > block number:        16989464
   > block timestamp:     1645569071
   > account:             0x30F43b79609781cEe3Be59f05eD6b1b4156458CE
   > balance:             0.24626074
   > gas used:            186963 (0x2da53)
   > gas price:           10 gwei
   > value sent:          0 ETH
   > total cost:          0.00186963 ETH

   Pausing for 10 confirmations...
   -------------------------------
   > confirmation number: 2 (block: 16989467)
   > confirmation number: 3 (block: 16989468)
   > confirmation number: 5 (block: 16989470)
   > confirmation number: 6 (block: 16989471)
   > confirmation number: 7 (block: 16989472)
   > confirmation number: 9 (block: 16989474)
   > confirmation number: 10 (block: 16989475)

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00186963 ETH


2_deploy_contracts.js
=====================

   Deploying 'ShidoInu'
   --------------------

Error:  *** Deployment Failed ***

"ShidoInu" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

Hope this helps you.

Pavon

1 Like

Hello Pavon,

Thank you very much for taking your time to look at this, much appreciated.

I didn't get the error with byte limit, but now I understand why I got the gas estimation error. Anyways it seems like it could be possible to deploy despite that size of the code. I had a feeling it was a bit hefty once it started to come close to 2000 lines.

I need to look into what the problem might be in the constructor, if there is some conflict there. I have to walk it through line by line.

Thanks again brother. I can get back to you here when I hopefully find a solution.

Cheers, Bjorn

1 Like

Sure thing, my man. Let me know if you need any help, and I'll help you to the best of my knowledge.

Have a great day and thanks again.

Pavon

Thanks man, I will try my best.

I realized I had the router for mainnet and not testnet with Pancakeswap, so thats one thing. For Uniswap its the same for mainnet and testnet.

Have a good one.