2

Is it possible to subscribe program by passing SOL program ID to track SOL transfers? I'd like to track the SOL transfers by subscribing blocks any help appreciated, thank you.

2 Answers 2

1

An alternative to "subscribing" is to poll using the getBlocksWithLimit and getBlock JSONRPC methods (or your favorite SDK's wrappers).

getBlocksWithLimit is a light-weight call, that takes a start_slot and count and returns all Slots which actually produced Blocks in that range. It can be polled periodically, starting from the slot height of last Block you've processed and with whatever count is a reasonable chunk of work for your application

getBlock can then be used to get the Block data for each slot returned by `getBlocksWithLimit. Since this call can be very heavy, it is preferred to keep the call rate to a minimum, hence ensuring you will actually get data with the lighter call

2
  • The reason why I'd like to track SOL transfers is that I'm working in a crypto exchange market and we will list SOL. If a customer deposits SOL , I'd like to catch the address to validate the deposit. Is it doable with your recommendations? I wanted to subscribe to the blocks but subscribeBlocks is unstable, it disconnects after 2 mins.
    – korimusk
    Commented Jul 20, 2022 at 8:38
  • 1
    What I proposed here is exactly how nearly every exchange I'm aware of indexes blocks for Solana. It is very flexible and robust, unlike websocket subscriptions
    – trent.sol
    Commented Jul 20, 2022 at 16:31
0

Yes sure, you can use Solana Web3 library for JS ,or if you use other programming language library for that language, and do something like this https://solanacookbook.com/references/local-development.html#subscribing-to-events . Also you can use direct JSON RPC API and handle WebSocket yourself and subscribe to account you want to track https://docs.solana.com/developing/clients/jsonrpc-api#accountsubscribe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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