1

I have a list of addresses, thousands, and I need to monitor incoming transactions to them. Some of them are native Solana addresses, other are tokens.

How will I get the last 3-5 transactions for a given address/account? The information I'll need is: assets, timestamp, value, from. That's, basic one.

How to do this? Does https://api.mainnet-beta.solana.com support it? I haven't found clear information.

P.S.

I'm using a language that's not a main-stream one, therefore I want to use an API for this rather than Solana SDK.

2 Answers 2

3

To get the last 1000 signatures for a specific address using the JSON RPC API, do the following:

curl https://api.mainnet-beta.solana.com/ \
  -X POST \
  -H "Content-Type: application/json" \
  -d $'[
    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getSignaturesForAddress",
      "params": ["Vote111111111111111111111111111111111111111",{"before": "oldestSignaturesOfLastFetch"}]
      }
  ]'

The above gets signatures for the account Vote111111111111111111111111111111111111111 before the signature oldestSignaturesOfLastFetch. From that, you can then use the individual signatures to get the transaction information using getTransaction.

4
  • Does getSignaturesForAddress have to be used? Can't a list of TXs be fetched without it -- directly?
    – Kum
    Dec 29, 2022 at 21:09
  • No, you have to use getSignaturesForAddress first. I'm sure some saas has both combined, but raw JSON RPC API requires both
    – Jacob Creech
    Dec 30, 2022 at 2:17
  • But even after having received getSignaturesForAddress, one would have to request last N transactions one by one? There's no way to pull them all at once?
    – Kum
    Dec 30, 2022 at 2:29
  • You can batch them using JSON RPC batching
    – Jacob Creech
    Dec 30, 2022 at 15:40
0

Reminder you can add param: ["limit": N] to getSignaturesForAddress to limit response to X amount of transactions. Can be combined with the before param. Then you can pass in the response signatures in one call using getParsedTransactions. Would recommend using ["maxSupportedTransactionVersion": 0] parameter to it as well.

Keep in mind this wont catch incoming SPL token transfers as the given address youre calling getSignaturesForAddress with won't be included in the accountKeys array when its on the receiving end, only its token account will.

So for completedness if you are worried about getting every tx you would have to get all the token accounts for a given address, parse the signatures, parse the token accounts signatures, organize them by blockTime, etc.

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.