Moralis Uniswap DEX

Hello, can someone help in regards to the list of tokens not populating? When I click to select tokens, the ‘token’ select box comes up but the list of tokens do not show!! I have also tried ‘Moralis.start’ as the new standard and although the full code is posted above, that also does not work correct for some reason.

Thank you in advance.

async function init() {
    await Moralis.initPlugins();
    await Moralis.enable();
    await listAvailableTokens();

}

async function listAvailableTokens(){
    const result = await Moralis.Plugins.oneInch.getSupportedTokens({
        chain: 'eth', // The blockchain you want to use (eth/bsc/polygon)
    });
    const tokens = result.tokens;
    let parent = document.getElementById("token_list");
    for (const address in tokens) {
        let token = tokens[address];
        let div = document.createElement("div");
        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;
        parent.appendChild(div);

    }
}

async function login() {
    try {
        currentUser = Moralis.User.current();
        if (!currentUser) {
            currentUser = await Moralis.Web3.authenticate();
        }
    } catch (error) {
        console.log(error);
    }
}
function openModal() {
    document.getElementById("token_modal").style.display = "block";
}
function closeModal() {
    document.getElementById("token_modal").style.display = "none";

}

init();

document.getElementById("modal_close").onclick = closeModal;
document.getElementById("from_token_select").onclick = openModal;
document.getElementById("login_button").onclick = login;
type or paste code here

Here is the modal:

<div class="modal" id="token_modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Select token</h5>
                <button id="modal_close" type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div id="token_list"></div>
            </div>
        </div>
    </div>
</div>

    <script type="text/javascript" src="./main.js"></script>
</body>

</html>type or paste code here

Hey @ProjekP

Your code works correctly. Check if you installed the Plugin to your server.

I suggest you to use Moralis.authenticate() instead of Moralis.Web3.authenticate().

Moralis.Web3 is an outdated syntax

Hi Yomoo, thanks. I shall try that. Plugin definitely installed but i shall change the Moralis.authenticate :slightly_smiling_face:

1 Like

Hello Yomoo. I still have an issue with the token list not populating. I’ve tried allsorts over the last couple of days. Something is wrong somewhere, despite the code looking spot on. Moralis.authenticate more reacts to the login button which populates metamask fine. I have deleted 1inch plugin and loaded again, and still no list populating…

Hi @ProjekP

Take a look at tutorial’s repo. Check how does this code work for you :man_factory_worker:

Hello Yomoo, Ok, I’ll have another play around. Thanks

Great help and thank you my brother. I followed the new updated syntax and have now got it working. One week later lol…plenty of patience and perseverance :grinning:

2 Likes

You are welcome!

Happy BUIDLing :rocket:

1 Like

Hey @ProjekP I’m trying to achieve what you’ve achieved. Can you help me out. Is your swap code open source?, If yes can I get the GitHub link? Thanks

This might be helpful https://youtu.be/XOvtnDx1m5c

1 Like

Thanks man.

I appreciate your response.