0

I am using solana web3js and have a public key for my wallet.

I want to console log every time someone sends me SOL. I’m interested in the amount of sol, and the public key of who went me the sol.

Is there a way to subscribe to my wallet and listen for this?

2 Answers 2

2

Quicknode has a good article that explains listening to an incoming transaction: https://www.quicknode.com/guides/solana-development/getting-started/how-to-create-websocket-subscriptions-to-solana-blockchain-using-typescript

1

You can use the accountSubscribe websocket endpoint and put in your wallet address, ie:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "accountSubscribe",
  "params": [
    "<YOUR_WALLET_AS_BASE_58>",
    {
      "encoding": "jsonParsed",
      "commitment": "confirmed"
    }
  ]
}

Note that this will only give you the new amount of SOL in the account. If you want to get information about the amount sent and the sender, you'll need to get the transaction that triggered the notification using getSignaturesForAddress and then getTransaction on the most recent signature in the return.

More information at https://solana.com/docs/rpc/websocket/accountsubscribe and https://solana.com/docs/rpc/http/getsignaturesforaddress and https://solana.com/docs/rpc/http/gettransaction

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.