EatTheBlocks Forum

Cannot read property 'dex' of undefined

Please help not sure why contract dex not working for me. I am also using the code in repo. Thanks for your help.

useEffect(() => {
const init = async () => {
const rawTokens = await contracts.dex.methods.getTokens().call();
const tokens = rawTokens.map(token => ({
…token,
ticker: web3.utils.hexToUtf8(token.ticker)
}));
const [balances, orders] = await Promise.all([
getBalances(accounts[0], tokens[0]),
getOrders(tokens[0]),
]);
listenToTrades(tokens[0]);
setTokens(tokens);
setUser({accounts, balances, selectedToken: tokens[0]});
setOrders(orders);
}
init();
}, []);

Looks like you haven’t deployed the dex, or are not on the correct network with Metamask.

PS: you can use markdown to format code on the forum.