I'm new to solana network and technology. I'm developing an application to confirm transaction receive to a specific wallet address on solana network. Right now I'm using this API "api.mainnet-beta.solana.com" .My question is how to get amount and symbol of a transaction ?
1 Answer
Assuming you've already identified the transactions that are interesting to you, you will find preTokenBalance
and postTokenBalance
fields in the transaction metadata, both with this structure.
To get the transfer amount, first coerce the
uiTokenAmount
field(s) into a number however is most convenient for the language you're using. Then take the difference of the two.The
mint
field can then be used to query something like the Solflare Unified Token List API for the extended token metadata, which contains they symbol.
-
Just wanted to add this regarding token symbol and name : with the token metadata being moved onchain, one can directly fetch the metadata account of a token and deserialize it, the new metaplex sdk does it farily trivially, this way if you dont trust an api and want to directly get it via the contract you can do so. Commented Jul 13, 2022 at 7:34
-