Fault while nothing change

Hello guys,

Iā€™ve got a problem.
While we are working on the dex, and still no faults so far.
but today ive started working again on it and see that the availeble token list isnt showing up.
it give the following fault:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ā€˜getSupportedTokensā€™)
at listAvailableTokens (main.js:22)
at init (main.js:12)

When i search in main.js line 12, i come to the 1inch plugin.
await Moralis.Plugins.oneInch.getSupportedTokens({

This line of code worked all the time, till today. Iā€™ve changed nothing to this line and it worked before.
Can someone help me please ?

Hi @Unsignme

Please provide at least the code you have, thank you!

For now, I can say that it looks like the oneInch plugin did not have time to load before you call it.

You can add await to the Moralis start function: `await Moralis.start({appId, serverUrl})

Hello @Yomoo
It worked all fine for days/weeks, till one day we get the fault code.

This is the whole line of code;

async function listAvailableTokens() {
const result = await Moralis.Plugins.oneInch.getSupportedTokens({
chain: ā€œbscā€, // The blockchain you want to use (eth/bsc/polygon)
});
tokens = result.tokens;
let parent = document.getElementById(ā€œtoken_listā€);
for (const address in tokens) {
let token = tokens[address];
let div = document.createElement(ā€œdivā€);
div.setAttribute(ā€œdata-addressā€, address);
div.className = ā€œtoken_rowā€;
let html = <img class="token_list_img" src="${token.logoURI}"> <span class="token_list_text">${token.symbol}</span> ;
div.innerHTML = html;
div.onclick = () => {
selectToken(address);
};
parent.appendChild(div);
}
}

from line 1 to line 24;

const serverUrl = ā€œserverā€; //Server url from moralis.io
const appId = ā€œIDā€; // Application id from moralis.io
const searchBox = document.querySelector(".search-box input");

let currentTrade = {};
let currentSelectSide;
let tokens;

async function init() {
await Moralis.start({ serverUrl, appId });
await Moralis.enableWeb3();
await listAvailableTokens();
currentUser = Moralis.User.current();
if (currentUser) {
document.getElementById(ā€œswap_buttonā€).disabled = false;
await tokenValue();
}
}

async function listAvailableTokens() {
const result = await Moralis.Plugins.oneInch.getSupportedTokens({
chain: ā€œbscā€, // The blockchain you want to use (eth/bsc/polygon)
});

Hi @Unsignme

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ā€˜getSupportedTokensā€™)
at listAvailableTokens (main.js:22)

You probably did not initialize the plugins.

Add:

Moralis.initPlugins();

In your init() function before you call await listAvailableTokens();

Thank you @dani for your fast respond.

I tried to update the plugin right now, and the problems are solved.