3

I tried to deploy a contract to Testnet with Remix (all Testnet return the same message) and I got this error:

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": "gas required exceeds allowance (30000000) or always failing transaction" }

But when I tried to deploy it in BSC Mainnet everything works fine with no errors. Any suggestions?

this is the relevant code

contract artemis is Context, IERC20, Ownable {
    // ...

    constructor() public {
        _rOwned[_msgSender()] = _rTotal;

        IUniswapV2Router02 _uniswapV2Router =
            IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);
        // Create a Pancakeswap pair for this new token
        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());

        // set the rest of the contract variables
        uniswapV2Router = _uniswapV2Router;

        //exclude owner and this contract from fee
        _isExcludedFromFee[owner()] = true;
        _isExcludedFromFee[address(this)] = true;

        emit Transfer(address(0), _msgSender(), _tTotal);
    }

    // ...
}

I upload the whole code here because its to long.

code

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
marvin
  • 45
  • 1
  • 6
  • Please edit your question and share the source code of your contract. The "always failing transaction" is the more probable reason stated in the error message. – Petr Hejda Apr 26 '21 at 07:19

1 Answers1

7
IUniswapV2Router02 _uniswapV2Router =
    IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);

// Create a Pancakeswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
    .createPair(address(this), _uniswapV2Router.WETH());

These lines in your constructor are trying to interact with a contract that exists on the mainnet. But you're on the testnet, where there's no contract on this address.

As stated in this post, the Pancake testnet router address is :

0xD99D1c33F9fC3444f8101754aBC46c52416550D1

So you need to replace the hardcoded address to this one.

w3spi
  • 4,380
  • 9
  • 47
  • 80
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • Thanks for your help...i was really stuck over here...can you please tell me if there is a way to change the maxTxAmount in my contract after i deployd . – marvin Apr 27 '21 at 16:54
  • @marvin I'm not sure what `maxTxAmount` you mean. If it's a variable with a setter function, you can execute the setter function to set the new value. If it's a constant (or a variable without a setter function), there's no way to change it, because the bytecode is immutable by design. – Petr Hejda Apr 27 '21 at 17:41
  • Thanks again for your answer.. uint256 public _maxTxAmount = 1000000000 * 10**6 * 10**9; i mean this...i dont think this si a constant...inside the contract it looks like this uint256 public _maxTxAmount = 5000000 * 10**6 * 10**9; and i need to make it uint256 public _maxTxAmount = 1000000000 * 10**6 * 10**9; Also is there another router address for ropsten network? Thanks in advance – marvin Apr 28 '21 at 03:17
  • In the case of your code (posted to the original question), you can affect the `_maxTxAmount` with the `setMaxTxPercent()` function. Mind that the function has the `onlyOwner` modifier, so you can execute it only from the `owner` address... Pancakeswap is an opensource, so there's pretty high chance there is another instance of their router, but I'm not aware of any. – Petr Hejda Apr 28 '21 at 07:17