3

I am trying to develop a deposit system like solcasino, I was wondering how can i have my client listen to some event whenever any deposit is made on some specific wallet and could provide the address of the depositor and the amount of sol. Amount and depositor's address is important as I have to update database based on that wallet address. I was looking into "accountSubscribe" but I wasn't sure if it will provide wallet address. My client is in Rust, if that's important.

2 Answers 2

4

accountSubscribe is exactly what you want, you will:

receive notifications when the lamports or data for a given account public key changes

In your case, you'll get notifications whenever the lamports in the wallet change, and can do whatever else you need at that point.

You can find the full information at https://docs.solana.com/api/websocket#accountsubscribe

Edit: I missed the part asking about the depositor.

Since accountSubscribe only gives you the updated state of an account, you'll need to fetch the transaction to get more information. Once you get a notification, you can use getSignaturesForAddress to see recent transactions.

With the signature, you can use getTransaction and search the preBalances and postBalances to see where the lamports came from.

More information on getSignaturesForAddress at https://docs.solana.com/api/http#getsignaturesforaddress and getTransaction at https://docs.solana.com/api/http#gettransaction

5
  • Thanks for the reply. I tried accountSubscribe but it only gives lamports data not the public keys of the depositor. is there anything I am missing?
    – eiquy3
    Jun 6, 2023 at 11:55
  • My apologies, I missed that part. I'll edit my answer
    – Jon C
    Jun 7, 2023 at 12:13
  • Thanks, I tried getSignaturesForAddress on getting event triggered from accountSubscribe and i got all the data i needed like change in lamports and address of depositor. Now i have doubt like if two transactions are done on same time and i get my event triggered after the second transaction has confirmed. My first transaction will be missed as i am only getting one last signature from getSignaturesForAddress. How can i tackle this issue? On what basis should i decide number of signatures so it includes all new transactions? Sorry for the noob question.
    – eiquy3
    Jun 8, 2023 at 11:25
  • This is certainly a possible situation! You might need to store a few recent transaction signatures locally, so that when you get the notification and get signatures, you'll know which ones you've already seen, and only request those that you haven't seen.
    – Jon C
    Jun 8, 2023 at 17:16
  • Thanks, I will try this approach.
    – eiquy3
    Jun 8, 2023 at 17:57
0

Is that correct way to poll (for example our service has 1 million+ address) each with getSignaturesForAddress? or Need to create PDA accounts (1million+) and monitor only Parent owner program account? Whats the industry standart way to listen deposits on large amount of addresses ?

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.