0

i want to get the balace of the tron wallet.
when i want to return it to show it on the web page with expressjs it print [object Promise]

var express = require('express');
var router = express.Router();
const TronWeb = require('tronweb');
const tronWeb = new TronWeb({
        fullNode: 'https://api.trongrid.io',
        solidityNode: 'https://api.trongrid.io',
        eventServer: 'https://api.trongrid.io'
    }
)
/* GET home page. */
const userBalance = async function() {
  const getUserBalance = await tronWeb.trx.getBalance("TNBE5fs2tGTnaJhCvd1Qy2BQ1k2j7Yv5zs")
  const userBalance = getUserBalance;
   return userBalance;
};
router.get('/', function(req, res, next) {
  //userBalance();
  res.render('index', {
      title: 'Express',
      userBalance: userBalance(),
  });
});

module.exports = router;

1 Answers1

0

You should write

router.get('/', async function(req, res, next) {
  const userBalance = await userBalance();
  res.render('index', {
      title: 'Express',
      userBalance: userBalance
  });
});
PaulShovan
  • 2,140
  • 1
  • 13
  • 22