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 6, 2019 in Others by Muhammad Ahmed
• 140 points
212 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 19, 2019 in Others by Hemant Gajbe
1,570 views
0 votes
2 answers
0 votes
1 answer

How to import data from a HTML table on a website to excel?

Hello  To import any HTML file in excel there ...READ MORE

answered Feb 10 in Others by gaurav
• 17,400 points
65 views
0 votes
1 answer

How to convert data from txt files to Excel files using python

Hi , there are few steps to ...READ MORE

answered Feb 16 in Others by Edureka
• 13,640 points
3,678 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 7, 2019 in Others by Frankie
• 9,830 points
989 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
1,979 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,240 points
252 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
• 69,210 points
302 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP