what I'm trying to do is to fork the Ethereum Mainnet on my local ganache blockchain in order to interact with smart contract like Uniswap on my local machine.
I forked the Ethereum network using ganache-cli and infura node provider and I found a simple reflection token on etherscan which I'm trying to deploy on my local forked blockchain installation.
The same code is installed fine on testnet using Remix.
The code of the constructor of the contract is the following:
constructor () {
_rOwned[_msgSender()] = _rTotal;
addAddress(_msgSender());
_otAddress = address(1);
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
// Create a uniswap 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[_otAddress] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromAntiWhale[owner()] = true;
_isExcludedFromAntiWhale[_otAddress] = true;
_isExcludedFromAntiWhale[address(this)] = true;
_isExcludedFromAntiWhale[address(uniswapV2Router)] = true;
_isExcludedFromAntiWhale[uniswapV2Pair] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
The truffle compile works fine, however when I try to migrate the contract to the local blockchain I get the following error:
"TokenCoin" ran out of gas. Something in the constructor (ex: infinite loop) caused gas estimation to fail. Try:
* Making your contract constructor more efficient
* Setting the gas manually in your config or as a deployment parameter
* Using the solc optimizer settings in 'truffle-config.js'
* Setting a higher network block limit if you are on a
private network or test client (like ganache).
My truffle config is the following:
require('babel-register');
require('babel-polyfill');
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
gasPrice: 0x01,
network_id: "*" // Match any network id
},
},
contracts_directory: './src/contracts/',
contracts_build_directory: './src/abis/',
compilers: {
solc: {
version: "^0.8.4", // Fetch exact version from solc-bin (default: truffle's version)
optimizer: {
enabled: true,
runs: 1
}
}
}
}