Tutorial Learn BSC Programming not Working on BSC Mainnet[SOLVED]

Hi guys,
i followed your youtube tutorial Learn BSC Programming (Binance Smart Chain) FULL COURSE Youtube link and it`s work on bsc testnet

and i tried to test it on bsc mainnet but not working, i cant got the data on my moralis dashbord like i have tested on tesnet , i have changed the logic.js , and do steps following Moralis doc: : 1.Created BSC Mainnet Server 2.Changed the Moralis.initialize application id and Moralis server URL using my profile on Mainnet Server 3. Changed the chainToQuery = 'bsc tesnet' to bsc`
4.Change my metamask wallet to bscmainet

I really appreciate if some one can help me to fix this ,
test url : Test bsc mainnet
source code:
Logic.js

Moralis.initialize("79wvBXO9HFgp9lgbcWAiFuGZeItjiko0QBbphX0y"); //Application ID
Moralis.serverURL = "https://bwjkht45wr6l.grandmoralis.com:2053/server"; //Server URL 

/* Valid values for chain in https://docs.moralis.io/moralis-server/transactions-and-balances/intro */
const chainToQuery = 'bsc'

async function login(){
    Moralis.Web3.authenticate().then(function (user){
        user.set("name", document.getElementById('username').value);
        user.set("email", document.getElementById('email').value);
        user.save();
        deactivateControls();
        populate();
    })
}

function deactivateControls(){
    document.getElementById('login').setAttribute("disabled", null);
    document.getElementById('username').setAttribute("disabled", null);
    document.getElementById('email').setAttribute("disabled", null);
}

async function populate(){
    const balances = await Moralis.Web3API.account.getTokenBalances({chain: chainToQuery}).then(buildTableBalances);
    const nft = await Moralis.Web3API.account.getNFTs({chain: chainToQuery}).then(buildTableNFT);
    const transtactions = await Moralis.Web3API.account.getTransactions({chain: chainToQuery}).then(buildTableTransactions);

}

function buildTableBalances(data){
    document.getElementById("resultBalances").innerHTML = `<table class="table table-dark table-striped" id="balancesTable">
                                                            </table>`;
    const table = document.getElementById("balancesTable");
    const rowHeader = `<thead>
                            <tr>
                                <th>Token</th>
                                <th>Symbol</th>
                                <th>Balance</th>
                            </tr>
                        </thead>`
    table.innerHTML += rowHeader;
    for (let i=0; i < data.length; i++){
        let row = `<tr>
                        <td>${data[i].name}</td>
                        <td>${data[i].symbol}</td>
                        <td>${data[i].balance/10**18}</td>
                    </tr>`
        table.innerHTML += row
    }
}

function buildTableNFT(_data){
    let data = _data.result;
    document.getElementById("resultNFT").innerHTML = `<table class="table table-dark table-striped" id="nftTable">
                                                            </table>`;
    const table = document.getElementById("nftTable");
    const rowHeader = `<thead>
                            <tr>
                                <th>ID</th>
                                <th>Type</th>
                                <th>Contract</th>
                            </tr>
                        </thead>`
    table.innerHTML += rowHeader;
    for (let i=0; i < data.length; i++){
        let row = `<tr>
                        <td>${data[i].token_id}</td>
                        <td>${data[i].contract_type}</td>
                        <td>${data[i].token_address}</td>
                    </tr>`
        table.innerHTML += row
    }
}

function buildTableTransactions(_data){
    console.log(_data)
    const current = ethereum.selectedAddress;
    let data = _data.result;
    document.getElementById("resultTransactions").innerHTML = `<table class="table table-dark table-striped" id="transactionsTable">
                                                            </table>`;
    const table = document.getElementById("transactionsTable");
    const rowHeader = `<thead>
                            <tr>
                                <th>Type</th>
                                <th>From/To</th>
                                <th>Value</th>
                            </tr>
                        </thead>`
    table.innerHTML += rowHeader;
    for (let i=0; i < data.length; i++){
        let type = "";
        if (data[i].from_address == current){
            type = "Outgoing";
            fromTo = data[i].to_address;
        }
        else {
            type = "Incoming";
            fromTo = data[i].from_address;
        }
        let row = `<tr>
                        <td>${type}</td>
                        <td>${fromTo}</td>
                        <td>${data[i].value/10**18}</td>
                    </tr>`
        table.innerHTML += row
    }
}




index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <!--Head Content-->
        <title>My First BSC Dapp</title>
        <!-- Required meta tags -->
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Links -->
        <!-- Make It Pretty Import the Bootstrap stylesheet -->
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
    </head>
    <body>
        <main>
            <div class="container">
                <div class="mt-2 mb-2">
                    <h1>Connect to Your Wallet</h1>
                </div>
                <div class="mt-2 mb-2">
                    <input id="username" type="text" class="form-control" placeholder="Username">
                </div>
                <div class="mt-2 mb-2">
                    <input id="email" type="text" class="form-control" placeholder="Email">
                </div>
                <div class="mt-2 mb-2">
                    <button id="login" class="btn btn-dark" onclick="login();">Connect MetaMask</button>
                </div>
                <hr>
                <div class="mt-2 mb-2">
                    <h2>Your Balances</h2>
                    <div id="resultBalances">
                    </div>
                </div>
                <hr>
                <div class="mt-2 mb-2">
                    <h2>Your NFTs</h2>
                    <div id="resultNFT">
                    </div>
                </div>
                <hr>
                <div class="mt-2 mb-2">
                    <h2>Your Transaction Statement</h2>
                    <div id="resultTransactions">
                    </div>
                </div>
            </div>
        </main>
    <!-- Scripts -->
        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
        <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
        <script src="static/logic.js"></script>
    </body>
</html>

Hey @tranceman

But your dapp works correctly:

yes i can see your data on my moralis dashboard,
i tried using chrome browser before, but it work when using dapps on my wallet,

thanks

1 Like

So is the problem solved?

yes, thanks in advance
I am so enthused to learn another features, Moralis is epic

2 Likes

Happy BUIDLing :man_factory_worker: