0

I want to know how to get transaction data like [from address] [to address] [amount] by providing the signature of the transaction. if it's by curl to get data from SOLANA main network API or SOLANA CLI

2 Answers 2

1

This Typescript function should achieve what you want. It will return basic details like you want, assuming transfer is the first instruction in the transaction.

const getTransferDetails = async (tx: string) => {
  const data = {
    method: 'getTransaction',
    jsonrpc: '2.0',
    id: "1",
    params: [
      tx,
      { encoding: 'jsonParsed', commitment: "finalized" }
    ],
  }

  const response = await fetch("https://api.mainnet-beta.solana.com", {
    method: "POST",
    body: JSON.stringify(data),
    headers: {
      "Content-Type": "application/json"
    }
  })


  const json = await response.json()
  if (!json.result) {
    return { receiver: null, sender: null }
  }

  // Notice I'm taking the zero index, because like I mentioned earlier, I'm assuming this transaction transfer instruction being first or the only one
  const instruction = json.result.transaction.message.instructions[0]

  // This will give you an object containing "destination", "source" and "amount"
  const { destination, source, amount } = instruction.parsed.info

  return { receiver: destination, sender: source, amount }
}

Ultimately, you would need to filter the returned parsed transaction data, so a CURL request would be a bit more difficult and not readable.

0

you can also use Bitquery Solana APIs it will be much easier. You can create a free developer account on Bitquery IDE and use it. Have a look at this saved query to get the transfer details like sender, receiver, amount. Bitquery has many powerful APIs to get on chain data for different chains like ethereum, bsc, arbitrum, solana, matic, etc.

Full disclosure: I work at Bitquery. Feel free to ask questions in our support channels. Telegram Channel link

enter image description here

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.