[SOLVED] How to check Token balance

How can I check if bep20 balance is up to a specific amount to perform a certain transaction

you can use this to get the native balance for an address: https://docs.moralis.io/moralis-server/web3-sdk/account#getnativebalance

// get mainnet native balance for the current user
const balance = await Moralis.Web3API.account.getNativeBalance();

// get BSC native balance for a given address
const options = { chain: "bsc", address: "0x...", to_block: "1234" };
const balance = await Moralis.Web3API.account.getNativeBalance(options);

BEP20 tokens balances:
https://docs.moralis.io/moralis-server/web3-sdk/account#gettokenbalances

const options = { chain: 'bsc', address: "0x...", to_block: "10253391" }
const balances = await Moralis.Web3API.account.getTokenBalances(options);

Is the address the contract address of the token, cause I just wanted the balance of a specific token from the user

the address is the address of your user wallet, this is an example of the output:

[
  {
    "token_address": "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
    "name": "Kylin Network",
    "symbol": "KYL",
    "logo": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c.png",
    "thumbnail": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c_thumb.png",
    "decimals": "18",
    "balance": "123456789"
  }
]

and from the output you can get the info to your specific token address that you are interested in

Now I understand how it works thanks

1 Like

This one is not working gives me
TypeError: Web3Api.getNativeBalance is not a function

any other way

It sure where from you got that, in example was

const balances = await Moralis.Web3API.account.getTokenBalances

I need a way to get the balance of current balance on current chain,

You can specify an address and chain as parameters

example of accessing the specific token and its balance from the output array?