4

How can i connect to a transaction server socket. I want to get updates when ever a new transaction happens.

2

There is an api endpoint for transactions available here.

https://www.stellar.org/laboratory/#explorer?resource=transactions&endpoint=all&values=eyJzdHJlYW1pbmciOnRydWV9&network=test

You are able to have it act like a socket by using the Server-Sent Events (streaming) mode that is an option at the bottom.

Notice how it changes the URL, and replicate that in your code.

2

The best way is using the SDK in streaming mode. For all transactions:

var channel = server.transactions()
  .forAccount(address)
  .cursor('now')
  .stream({
    onmessage: function(tx) { do something with tx },
    onerror: function(error) { log it }
  });

For payments only:

var channel = server.payments()
  .forAccount(address)
  .cursor('now')
  .stream({
    onmessage: function(payment) { do something with payment },
    onerror: function(error) { log it }
  });

To close the channel simply call itself as a method channel()

Ref https://www.stellar.org/developers/js-stellar-sdk/reference/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.