So please i have an error "currentTrade is not defined at HTMLDivElement.selectToken"

hello dear im new dev from your school only not educated in professional school but you are the best school MORALIS TEAM thank you for all , so please i have an error “currentTrade is not defined
at HTMLDivElement.selectToken”
copying a how to create a DEX full course Like Uniswap FULL" in youtube


<title>Vanilla Boilerplate</title>

<script src="[email protected]/dist/web3.min.js"></script>

<script src=""></script>

<script src=""

integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

 <script src=""



<link rel="stylesheet" href=""

integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<link rel="stylesheet" href="./style.css">
<nav class="navbar navbar-expand-lg navbar-light bg-light">

    <a class="navbar-brand" href="#">illimited Pixel</a>

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"

        aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">

        <span class="navbar-toggler-icon"></span>




      <button id="btn-login" class="btn btn-outline-primary my-2 my-sm-0" type="submit">Sign in with Metamask</button>

      <button id="btn-logout">Logout</button>

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



    <div class="collapse navbar-collapse" id="navbarSupportedContent">

        <ul class="navbar-nav mr-auto">

            <li class="nav-item active">

                <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>






<div class="container">

  <div class="row">

      <div class="col col-md-6 offset-md-3" id="window">


        <div id="form">

            <div class="Swapbox">

                <div class="Swapbox_select token_select" id="from_token_select">

                 <img class="token_image" id="from_token_img">  

                 <span id="from_token_text"></span>


                <div class="Swapbox_select">

                    <input class="number form-control" placeholder="amount" id="from_amount">



            <div class="Swapbox">

                <div class="Swapbox_select  token_select" id="to_token_select">

                  SELECT TOKEN                        


            <div class="Swapbox_select">

                <input class="number form-control" placeholder="amount" id="from_amount">



        <button class="btn btn-large btn-primary btn-block" id="Swap_button">




<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>



    <div class="modal-body">

      <div id="token_list"></div>  




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


serverUrl = “”;


Moralis.start({ serverUrl, appId });

async function init(){

await Moralis.initPlugins();  

     await listAvailableTokens();


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;




function selectToken(){


let address =“data-address”);


currentTrade[currentSelectSide] = tokens[address];




function renderInreface(){

document.getElementById(“from_token_img”).src = currentTrade.from.logoURI;

document.getElementById(“from_token_text”).src = currentTrade.from.symbol;


async function login() {

let user = Moralis.User.current();

if (!user) {

try {

  user = await Moralis.authenticate({ signingMessage: "The Swap" })



} catch(error) {





function openModal(side){

currentSelectSide = side;

document.getElementById(“token_modal”).style.display = “block”;


function closeModal(){

document.getElementById(“token_modal”).style.display = “none”;


async function logOut() {

await Moralis.User.logOut();

console.log(“logged out”);



document.getElementById(“modal_close”).onclick = closeModal;

document.getElementById(“from_token_select”).onclick = (() => {openModal(“from”)});

document.getElementById(“btn-login”).onclick = login;

document.getElementById(“btn-logout”).onclick = logOut;



margin-top: 50px;

background-color: black;

color: cornsilk;


padding: 15px;

block-size: 350px;  

border-radius: 20px;

box-shadow: 0 0 15px rgb(0, 255, 255);





    float: right;


    .Swapbox {

        overflow: auto;

        margin-bottom: 28px;

        background-color: #41cbab;

        text-shadow: 0 0 10px black;

        border: 1px solid #0400ed;

        border-radius: 35px;

        margin-right: -5px;



    padding: 10px 0;



     background-color: rgb(0, 134, 40);

     cursor: pointer;



    background-color: grey;

    cursor: pointer;



    margin-top: -412px;



    width: 40px;

    overflow: scroll;



    height: 700px;

    overflow: scroll;



    padding: 5px 10px;



    background-color: rgb(155, 155, 155);

    cursor: pointer;


looks like you just didn’t defined currentTrade function here

1 Like

Please dear YosephKS how can i do defined currentTrade im just learning now , im a noob dev :slight_smile: but i will learn from moralis

Hey man define it like this

const currentTrade = () => {
 // this is where your logic goes

Unfortunately I have no idea what’re you trying to do inside the function

1 Like

i try to show the token box logo when i clic on it and the token info

when i click on specific token this dosen’t show the logo in the select box

i get an error in the console: main.js:41 Uncaught ReferenceError: currentTrade is not defined
at HTMLDivElement.selectToken (VM803 main.js:41:3)
selectToken @ main.js:41

const currentTrade = (renderInreface) =>
{(“from_token_img”)} // like this ?

hmmm not very sure what are you doing here?

1 Like

i need to show the token logo and text name when i clic on a specifique token

i hope you can help me to evolve ,thank you very much for your time .