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
437 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
1 answer

Unable to import data in excel from another website using VB code

Replace : Set ieTable = ieDoc.all.Item("report-table") With: Set ieTable = ...READ MORE

answered Sep 21, 2022 in Others by narikkadan
• 63,420 points
507 views
0 votes
1 answer

How to return a result from a VBA function

You must associate the value with the ...READ MORE

answered Nov 4, 2022 in Others by narikkadan
• 63,420 points
1,294 views
0 votes
1 answer

Using Visual Basic to pull data from within a range to use in an Excel function

Use AVERAGEIFS instead of the full range. ...READ MORE

answered Jan 14, 2023 in Others by narikkadan
• 63,420 points
307 views
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
2,403 views
0 votes
2 answers
0 votes
1 answer

How to send Bitcoins with node.js?

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

answered Jul 20, 2018 in Blockchain by Christine
• 15,790 points
3,157 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
521 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
595 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP