EatTheBlocks Forum

Router error while deploying contract in Flashloan course?

When I try to deploy my contract, it compiles ok, but under 2_deploy_contracts.js I get a “TypeError: Cannot read property ‘router’ of undefined” at addresses.uniswap.router ?
My 2_deploy_contracts.js :

const Flashloan = artifacts.require("Flashloan.sol");
const { mainnet: addresses } = require('../addresses');

module.exports = function(deployer, _network, [beneficiaryAddress, _]) {
deployer.deploy(
    Flashloan,
    addresses.kyber.kyberNetworkProxy,
    addresses.uniswap.router,
    addresses.tokens.weth,
    addresses.tokens.dai,
    beneficiaryAddress
  );
}; 

If I try to run arbitrage.js I get “TypeError: Cannot read property ‘address’ of undefined” at Flashloan.networks[networkId].address in run-arbitrage.js.
Does anybody have any idea what could be the issue ?
Thx

You need to deploy Flashloan first. Then for uniswap, what do you have in addresses/uniswap-mainnet.json?

1 Like

Yes agreed, I have to deploy first with truffle migrate --reset --network mainnet the run run-arbitrage.js. Hmm in my addresses I only have
kyber-mainnet.json, tokens-mainnet.json and index.js, uniswap and dydx are missing :face_with_raised_eyebrow:. Should I create the missing .json files from the repo myself ? Thx

I figured it out, I had to add the dydx and uniswap require in index.js and add also the mainet :slight_smile:

1 Like

Hi, I am also facing the same issue.

I have deployed the smart contract to the mainnet.

I can see the contract address on etherscan.

However, I am not able to view the address on the flashloan.json.

Kindly help.
Thanks

You can use etherscan to find the tx that deployed the contract, by searching with the deploying address. In this tx you will find the address of the deployed contract.

1 Like

Thanks. It is working now, however getting the below error.

“connection”:“close”,“server”:“Apache”,“vary”:“Origin,Accept-Encoding”},“body”:"{“jsonrpc”: “2.0”, “id”: 43, “error”: {“code”: -32000, “message”: \

“Monthly capacity limit exceeded.
Visit https://dashboard.alchemyapi.io/settings/billing to upgrade your scaling policy for continued service.”}}"

Kindly suggest where to add the API Key.

Thanks

As the error message says, you exceeded your monthly free quota on Alchemy API.
So either upgrade to a paid account there, or use another Ethereum API like Infura.

1 Like

Hi, I have created an account in Alchemy and have the api key, I am not sure where to add the Key in the code. Kindly suggest.
Also sometimes I get Unable to pay dydx loan. Kindly let me know how much minimum ether should I have in my wallet.
Thanks

API key and url configuration in .env file.
Here is an example.

Not sure what you mean by being unable to pay dydx loan?