Unable to return data to main function from promise

+2 votes

Hi, i am fairly new to node js development and I am trying to build a back-end using node js and i have created a following controller in my code.

exports.bridge_b2b_transfer = function(req, res, next){
    let data = bnb.Transfer_b2b(req.body.bnb_wallet)
    console.log(data)
}

But it returns empty data.

I have tried to converting calls to asyncawait but with no success.and then i tried to use callbacks but grasping the concept is really difficult for me.

httpClient
        .get(sequenceURL)
        .then((res) => {
            const sequence = res.data.sequence || 0
            return bnbClient.transfer(addressFrom, addressTo, amount, asset, message, sequence)
        })
        .then((result) => {
            console.log(result);
            if (result.status === 200) {
              console.log('success', result.result[0].hash);
            } else {
              console.error('Error: ', result);
            }
        })
        .catch((error) => {
          console.error('error :', error);
          return error
        });

Output is printed where console is used but i want to return data to my main controller which is calling this function from another file. But as it is, it doesn't and data is undefined.

Sep 5 in Others by Muhammad Ahmed
• 140 points
13 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
0 answers

How to handle large http response data from observer in Angular application to avoid browser crash?

Suppose we have a angular application which ...READ MORE

Apr 18 in Others by Hemant Gajbe
66 views
0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 6 in Others by Frankie
• 9,810 points
27 views
0 votes
0 answers

I am getting this data from my server

May 29 in Others by anonymous
22 views
0 votes
0 answers

unable to connect to internet in edureka VM

i am unable to connect to internet ...READ MORE

Jun 6 in Others by Ashok
• 120 points
19 views
0 votes
1 answer

How to send Bitcoins with node.js?

This website https://blockr.io/tx/push will successfully do the bitcoin transaction. You ...READ MORE

answered Jul 20, 2018 in Blockchain by Christine
• 15,790 points
351 views
0 votes
1 answer

Running a childProcess as shell script with node.js server

Here's what I think, you could pass ...READ MORE

answered Aug 14, 2018 in IoT (Internet of Things) by DataKing99
• 8,130 points
44 views
0 votes
1 answer

How to read the ETH value and other token values from an account?

You can do this eth.accounts shows you all known ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 67,520 points
31 views