As I understand, stellar block-chain is actually the ledgers using the previous hash to connect to its prev ledgers down to genesis ledger.

my question is: how can i monitor the ledgers in order to not lose transaction of my account?

another question regarding that : if i will use the server.transactions for my account - is the list i will get contains only the approved transactions by the chain? or it can contain transactions which still need to be approved and get into a ledger? hope my question was clear because i am confused on this matter. thanks


If I understood your correctly, you want to track payments for an account. It's quite simple, streaming allows you to listen for payments/transactions.

Using JS SDK:

const {Server} = require('stellar-sdk')
//connect to the Horizon testnet
const horizon = new Server('https://horizon-testnet.stellar.org');
//stream payments
const stopStreaming = horizon.payments()
  .forAccount('GA...5N')  //account public key
  .cursor('now')          //stream only recent payments
  .stream({               //subscribe to payment stream
    onmessage: payment => console.log(payment)

If you want to get notifications about arbitrary transactions/operations/effects (like trades or account settings changes) you may subscribe for horizon.transactions() or horizon.effects() notifications in the same way.

Check basic code examples here.

In general, you don't need to monitor ledger to retrieve the data. Horizon server exposes REST API endpoints that allow you to query ledger/account/transactions data directly.

if i will use the server.transactions for my account - is the list i will get contains only the approved transactions by the chain?

Yes, Horizon returns only approved transactions.

  • ok great! but horizon is the testnet. what happens in the liveNet? Dec 26 '18 at 10:28
  • Exactly the same. Just specify https://horizon.stellar.org instead of https://horizon-testnet.stellar.org and do not forget to invoke StellarSdk.Network.usePublicNetwork() before creating a transaction, otherwise transaction signatures will be invalid. Check the link I provided in my answer. You'll find code examples with extensive comments.
    – Orbit Lens
    Dec 26 '18 at 11:25
  • thanks alot!. i got 2 more questions 1 regarding your last comment: 1. if all transactions list are approved by consensus, can i get transactions related to my account that are "pending" or waiting to be approve? because i saw new ledger every few moments. 2. can i use local node to connect to the server instead using api call? Dec 27 '18 at 7:46
  • There is no way to view "pending" transactions. Average tx confirmation time on Stellar is 4 seconds (and all transactions are considered final after 1 confirmation), so there is no need to check the pending tx mempool as you often do with BTC. You can use local node, but you will need to install Horizon locally anyway. SDKs communicate with the network only via Horizon API interface. In general, I'd recommend you to start using public https://horizon-testnet.stellar.org for prototyping.Moreover, deploy your own node only if you need to. Most projects are doing just fine with public Horizon.
    – Orbit Lens
    Dec 27 '18 at 12:28

Consensus is met by the network before any ledger is written. All transactions that appear in a ledger are approved and permanent.

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.