solana-labs / solana

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://solanalabs.com
Apache License 2.0
13.03k stars 4.19k forks source link

How to subscribe transaction on account #19488

Closed stone89son closed 2 years ago

stone89son commented 3 years ago

Problem

I am building a trading platform. When a user orders a Buy token, they will have to send SOL to my SOL account. The part I'm building is getting real time that transaction and adding it to the database, where in Solana Blockchain I must is research? Thank for read and help me.

fred227 commented 2 years ago

hi, the best is I think to subscribe off-chain using

         connection!.onLogs(PUBKEY_OF_YOUR_ACCOUNT,
         ( logs, context ) => getlogssubscribe( logs,context ),
         'finalized',
         );

then in getlogssubscribe you call an on-chain program and send the tx signature you just get. in that on-chain program you can use https://docs.rs/solana-client/latest/solana_client/rpc_client/struct.RpcClient.html#method.get_transaction to get infrormation about the tx. if is it ok, write in your database

steveluscher commented 2 years ago

Thanks for your question!

We want to make sure to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track issues that affect the development of Solana itself.

Questions like yours deserve a purpose-built Q&A forum. Please post your question to the Solana Stack Exchange using this link: https://solana.stackexchange.com/questions/ask