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.

Hi @jklepatch, I’m having the same problem here.

The contracts are deployed and I am in the ganache network.

I don’t know what to do.

Need help.

Are you sure the blockchain is running and Metamask is connected to it with correct parameter? Have you tried reloading the frontend with cache clearing?