Is there any way to call Multichain API in synchronously in node JS ?

+1 vote
Is there any way to call Multichain API in synchronously in node JS ? I am using multichain apis using Multichain-node where every call to multichain is going in Async way. How can i call it in Synchronous way ?
asked Dec 10, 2018 by sufyan ahmad

1 Answer

+2 votes

You can try using either:

  1. Promises:
  2. Await, Async Model:

I think Multichain itself doesn't support it natively because blockchain are generally multithreaded and async

answered Dec 11, 2018 by SDVII
I used async and awiat but did not return me any response. please look at this code'/getAddressBalances', authenticate,async function (req, res) {
  var  err, info= await multichain.getAddressBalances({ address: data.address })
    if (err) {
      res.status(400).send({ error: err.message });
    else {
I am not sure why it isn't working for you because I only have this much code to work with. However, did you try and call MC's native RPC API instead of using the community SDK?

Oh, can you please share your MC version?
I am following this link
And how i can call  MC's native RPC API ?
MC version is :1.0.6
First of all, you can call the RPC the same way you call any API, jQuery and axios are good options. It would have this kind of structure:

    url: 'url of your node with port',
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify( your call parameters including method name and required data ),
    success: function(response){
    error: function(){

Second of all, the SDK you are using is a community made one, so you might run into some issues, not to mention that it doesn't support the newest beta versions of MC
Oh, that's looking nice. Let me try in that way. Thanks @SDVII