I am trying to use Nodejs tron library to create pair of wallet address and here is my code:
app.js
var app = require('express')()
var http = require('http').createServer(app)
var wallet_engine = require('./function')
app.get('/', function (req, res) {
result = wallet_engine.create_wallet_trx()
console.log(result)
res.send(result)
})
//////server listen
http.listen(8443, function () {
console.log('listening on *:8443')
})
and here is my function.js
module.exports = {
create_wallet_trx: function () {
////////generate TRX Address
var { HdTronPayments } = require('@faast/tron-payments')
var keys = HdTronPayments.generateNewKeys()
var tronPayments = new HdTronPayments({ hdKey: keys.xprv })
var address = tronPayments.getPayport(356)
var privateKey = tronPayments.getPrivateKey(356)
var trx_wallet = { privateKey: privateKey, address: address }
console.log(trx_wallet)
return trx_wallet
},
}
The problem is when i check console.log(trx_wallet) the result is there and i can see generated public and private key, also after returning data, console.log(result) is displaying data, but res.send(result) shows me empty json.
this is console.log() results
{
privateKey: Promise {
'B88BB56DAB80DB681765A0C07197DD23BB8E2FAD195BF9D0ECD09F5F8FC54297'
},
address: Promise { { address: 'TYCJSKERHReUXacw9wLorZYLDoijevvsVK' } }
}
and this is the result on my browser:
{"privateKey":{},"address":{}}
i know this is because of Nodejs Async system and i should wait to promise gets the value but i don't know how to wait for promise to get complete and then prints the result on my browser screen.