I was going through the flashloan course and I was having trouble with section 13 Pull Kyber Prices.
I am getting this error
(node:43614) UnhandledPromiseRejectionWarning: Error: This contract object doesn't have address set yet, please set an address first
Here is my full code:
require('dotenv').config();
const Web3 = require('web3');
const abis = require('./abis');
const { mainnet: addresses } = require('./addresses');
const web3 = new Web3(
new Web3.providers.WebsocketProvider(process.env.INFURA_URL)
);
const kyber = new web3.eth.Contract(
abis.kyber.kyberNetworkProxy,
addresses.kyber.kyberNetworProxy
);
const AMOUNT_ETH = 100;
const RECENT_ETH_PRICE = 2400;
const AMOUNT_ETH_WEI = web3.utils.toWei(AMOUNT_ETH.toString());
const AMOUNT_DAI_WEI = web3.utils.toWei((AMOUNT_ETH * RECENT_ETH_PRICE).toString());
web3.eth.subscribe('newBlockHeaders')
.on('data', async block => {
console.log('New Block Recieved # ' + block.number);
const kyberResult = await Promise.all([
kyber
.methods
.getExpectedRate(
addresses.tokens.dai,
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
AMOUNT_DAI_WEI
)
.call(),
kyber
.methods
.getExpectedRate(
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
addresses.tokens.dai,
AMOUNT_ETH_WEI
)
.call()
]);
console.log(kyberResults);
})
.on('error', error => {
console.log(error);
});
The error that I am getting is this:
(node:43614) UnhandledPromiseRejectionWarning: Error: This contract object doesn't have address set yet, please set an address first.
at Object.ContractNoAddressDefinedError (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-core-helpers/lib/errors.js:122:16)
at Object._processExecuteArguments (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-eth-contract/lib/index.js:728:22)
at Object._executeMethod (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-eth-contract/lib/index.js:744:68)
at Subscription.<anonymous> (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/run-arbitrage.js:34:18)
at Subscription.emit (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/eventemitter3/index.js:181:35)
at /Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-core-subscriptions/lib/subscription.js:242:35
at Array.forEach (<anonymous>)
at Object.callback (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-core-subscriptions/lib/subscription.js:234:28)
at WebsocketProvider.data (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-core-requestmanager/lib/index.js:99:73)
at WebsocketProvider.emit (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/eventemitter3/index.js:181:35)
at /Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-providers-ws/lib/index.js:104:19
at Array.forEach (<anonymous>)
at WebsocketProvider._onMessage (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/web3-providers-ws/lib/index.js:102:69)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/yaeti/lib/EventTarget.js:115:12)
at W3CWebSocket.onMessage (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/websocket/lib/W3CWebSocket.js:234:14)
at WebSocketConnection.<anonymous> (/Users/wealthywhyte/Desktop/Solidity/profitable-flashloanz/node_modules/websocket/lib/W3CWebSocket.js:205:19)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:43614) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:43614) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I believe that the problem is lines 31 and 38 after the method ".getExpectedRate" I am just not sure what to switch those addresses that he provided out with.