Hey!
I am trying to deploy Uniswap to Ganache to test my code afterwards in my local net. However, after publishing the Uniswap contract, I am passing the address it to the constructor of my own contract. But somehow, this fails with following error message:
Error: *** Deployment Failed ***
"MyContract" 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.
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:75:1)
at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:218:1)
at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:147:1)
Truffle v5.3.9 (core: 5.3.9)
Node v14.16.0
However, the UniswapContract was published successfully. My contract’s constructure requires to parameters which are passed in the deploy method (see code below).
var myToken = artifacts.require("MyToken");
const json = require('@uniswap/v2-core/build/UniswapV2Factory.json')
const contract = require('@truffle/contract');
const UniswapV2Factory = contract(json);
UniswapV2Factory.setProvider(this.web3._provider);
module.exports = function(deployer, network, accounts) {
console.log(accounts);
deployer.deploy(UniswapV2Factory, accounts[9], { from: accounts[9]}).then(() => {
console.log("Uniswap deployed");
console.log(UniswapV2Factory.address);
return deployer.deploy(myToken, accounts[1], UniswapV2Factory.address);
});
}
This is the constructor of my Contract:
constructor(
address payable address1,
address uniswapRouterAddress
) {
_address1 = address1;
_rOwned[_msgSender()] = _rTotal;
// Testnet: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1
// Main: 0x10ED43C718714eb63d5aA57B78B54704E256024E
// uniswapAdress
IUniswapV2Router02 _uniswapV2Router =
IUniswapV2Router02(uniswapRouterAddress);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
emit Transfer(address(0), _msgSender(), _tTotal);
}
I’ve also had a look at the official documentation of Uniswap which is unfortunately still WIP and does not help to solve my problem. Even similar posts did not lead to a solution, since the contract of Uniswap is published but my contract cannot handle it?
I am very new to Solidity and Truffle, however I have several years of software developing experience.
Environment
I am running Truffle v5.3.9 with Ganache v2.5.4 on OS X.
Any help is very appreciated!
Best regards,
EDIT: I think I am missing something on the Uniswap Part, commenting the Uniswap Part out, solves the issue. Also, publishing on the BSC Testnet works fine.
EDIT 2: I have found a way to fork the main net to work with already published contracts → Alchemy. But I would still like to hear other opinions