How to track token transfers on Solana?

Viewed 627

I know that to track transactions on Ethereum you should use web3 or ethers WebSocket provider and listen to specific events, then filter by logs if needed. How similar thing can be done on Solana?

My guess is to use Connection class from web3.js and onLogs method, but I do not know how to construct log filters and I could not find any example. Anyone has experience with that?

1 Answers

If you want to track all transactions on Solana, you can use the currently new and unstable blockSubscribe method, which sends you whole blocks with all the transactions within. You can add additional filtering for a program or account that you care about: https://docs.solana.com/developing/clients/jsonrpc-api#blocksubscribe---unstable-disabled-by-default

Otherwise, if you only care about transfers, you can only subscribe to the system program (11111111111111111111111111111111) for SOL transfers, and the SPL Token program (TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA) for any other transfers using the programSubscribe endpoint: https://docs.solana.com/developing/clients/jsonrpc-api#programsubscribe

Related