So here is the following i am trying to build.
I have a test case on https://test.ncscrypto.online/
We are building a token contract that has the abbility to buy gold with tokens.
for this i want the users to login with their wallet and see.
The token, symbol and Balace are taken from the wallet.
The dollar is a calculation but i really want this to be the live price of the token in dollar, also if it is possible only 2 number behind the comma, so as in example $79.64
If it is also possible the token in Euro price (actual price)
And as last we want to create a solution that the dollar price will be calculated for real gold price in gramm’s. Is this all possible and if yes how and what must i edit in the code:
const serverUrl = “";
const appId = "”;
Moralis.start({ serverUrl, appId });
/* 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> <th>Dollar</th> <th>Euro</th> </tr> </thead>
table.innerHTML += rowHeader;
for (let i=0; i < data.length; i++){
let row = `
${data[i].name}
${data[i].symbol}
${data[i].balance/10starstar18}
$${data[i].balance/10starstar18star0.000000550663star1000000}
€${data[i].balance/10starstar**180.000000550663star1000000star*0.88125}
</tr>`
table.innerHTML += row
}
star = multiplier sign