2
votes

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

1
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

1 Answers

6
votes
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.