Hello everyone,
The newbie that I am still has a little problem so I allow myself to ask for a little help.
I would like to display the BNB balance of a wallet on my website.
The code is simple and short, when I open the console of my browser the balance is displayed but on the site page I have [object Object].
Here are the details:
Html:
<div class="balance1">
<div id="balance">
<p>Balance:</p>
<div id="balance"> BNB</div>
</div>
</div>
<script type="text/javascript" src="./main1.js"></script>
main1.js:
Moralis.initialize("5JNM9X1Nq8ciDngst2pNBUrSoThG5a7jBPYUvrZM"); // Application id from moralis.io
Moralis.serverURL = "https://xsmb9wqekxnl.moralishost.com:2053/server"; //Server url from moralis.io
async function getBalance() {
balance = await Moralis.Web3API.account.getNativeBalance({chain: "bsc", address: "0x67422A4b99D5a22094e54D4e7Ba2Da36431d5C50"});
console.log(balance)
let ethBalance = balance.ethBalance + " BNB"
document.getElementById("balance").innerHTML = balance;
}
getBalance();
Console:
When I click on the โXHR finishedโ link of the console I have this:
{โcodeโ: 141, โerrorโ: โ[object Object]โ}
Thanks in advance for the help