[SOLVED] Display BSC Contract Info

what to test? I just tested, that function doesn’t return anything, it is only using console.log(y), and it prints ‘9’ in may case

yeah correct ,is this code working for u ? bcz in my console its not showing anything

I wrote this:

bsc20_ABI = [
      {
        constant: true,
        inputs: [],
        name: "getNumberOfDividendTokenHolders",
        outputs: [
          {
            internalType: "uint256",
            name: "",
            type: "uint256"
          }
        ],
        stateMutability: "view",
        type: "function"
      },
    ];

y = await Moralis.Web3API.native.runContractFunction({
        chain: "bsc",
        address: "0x28e4f32fa7e842ad0a6e530bb6b4ec03b36d5078",
        function_name: "getNumberOfDividendTokenHolders",
        abi: bsc20_ABI,

      })

console.log(y)

in particular you don’t call that function divtokenholders in your code.

Yeahhh my mistake iss that I m pasting the code with async function in browser console and did not call it ! While I call it in my main js

sir everything done i want to show usercpt balance and all function whigh i call in frontend html …
i make h2 heeading with cpt id then i print it on frontend but it not showing any value to frontend

let b = usercptBalance()
 b.then(
   function(value){
     console.log(value);
     document.getElementById(cpt).innerHTML =value;},
     function(error) {console.log(error);}
   
 );
```   this code i do to show in frontend part

this works fine? and document.getElementById(cpt).innerHTML =value; doesn’t work?

Yess in console it is working properly… but when I try to show on my frontend html it don’t work

Only I make h2 heading and give I’d cpt to it !

I

document.getElementById(cpt).innerHTML =value

It don’t works

what is cpt in that context?

Cpt is I’d of h2 heading

you can test that command separately into your browser console until it works:

you can write: document.getElementById("cpt").innerHTML ="4" for example and make changes until it works

it works but i want to show 4 read function on frontend in this way
as i do code in this syntax totalsupply is showing undefined …
i dont reurn anything in tsupply function dats why its happening ?

<h2 id="hd"></h2>
      ERC20_ABI = [
  {
    constant: true,
    inputs: [],
    name: "totalSupply",
    outputs: [{ name: "", type: "uint256" }],
    payable: false,
    stateMutability: "view",
    type: "function",
  },
  ];
  async function tsupply(){
     const x = await Moralis.Web3API.native.runContractFunction({
  chain: "bsc",
  address: "0x28e4f32fa7e842ad0a6e530bb6b4ec03b36d5078",
  function_name: "totalSupply",
  abi: ERC20_ABI,
})
  console.log(x);
      }
const x = tsupply()

    x.then(
        function(value) {
               console.log(value);
               document.getElementById("hd").innerHTML = value;},
        function(error) {console.log(error);}
      );

yes, you have to return x in that tsupply function

async function tsupply(){
     const x = await Moralis.Web3API.native.runContractFunction({
  chain: "bsc",
  address: "0x28e4f32fa7e842ad0a6e530bb6b4ec03b36d5078",
  function_name: "totalSupply",
  abi: ERC20_ABI,
})
  return x;
      }

const x = await tsupply()
document.getElementById("hd").innerHTML = x;

yeah sir! it works when i replace await with normal const x= tsupply()
bcz i have to put again async function when i go through main js file …

and now i print all read functions
can u tell any way to used .tofixed to give decimals in the value but it dont works

<h2 id="hi"></h2>

  <script>
    /* Moralis init code */
    const serverUrl = "https://4l81fhpvqkit.usemoralis.com:2053/server";
    const appId = "pfaPMZpSl0COD4qDiZ6ytcu2ePIMaPWI2pSrhTZm";
    Moralis.start({ serverUrl, appId });

    async function login() {
      let currentuser = Moralis.User.current();
      if (!currentuser) {
       currentuser = await Moralis.authenticate({ signingMessage: "welcome to crypto planet " })
       
      }
      
      console.log("logged in user:", currentuser);
      console.log(currentuser.get('ethAddress'));
     this is for  printing cpt balance after user login 
      const tokenBalance = usercptBalance()

      tokenBalance.then(
        function (value) {
          console.log(value);
          document.getElementById("cpt").innerHTML = value;
        },
        function (error) { console.log(error); }
      );```

you can not use this code directly?

Yeahhh it works for browsers console but when I do with main js I removed await bcz again I have to make it in a async function!

But my problem is now to put decimals after 18 in every uint256 function bcz I try with .tofixed() but it did not work

Here is my code for login function in this function I have to put 18 decimals on frontend …

What is the problem that you have with using an async function?

when i m using await tsupply()
it shows in console that await works with async function

but when i do without await it works …
bdw is there any problem if i dont use await ? bcz code is completely running fine

it is fine if you are not using await, there is only an equivalent syntax with or without await, both of them work fine, with await is less code used sometimes