2

Creating an spl-transfer transaction:

const transaction = new Transaction().add(
  createTransferInstruction(
    // Pretend this is filled in
  )
)

const signature = await sendAndConfirmRawTransaction(..)

Assuming I only have access to signature, how can I confirm the transaction's sender, recipient, token transfer amount, and the token's public key?

1 Answer 1

2

You can use the getTransaction method on the connection class to get details on the transaction with a signature.

async function getTransactionFromSignature() {
  // setup code for example
  const connection = new web3.Connection(
    web3.clusterApiUrl("devnet"),
    "confirmed"
  );
  // end setup code

  const signature =
    "4x96CKaqStrBSW436RuTp4H7qFC4tACfQDMdWJm8LWBHTnXVf7yUdvE4J5btcz63RiC7Pnk7SP4P8QckLsh8rEh5";

  const response = await connection.getTransaction(signature);
  const message = response.transaction.message;
  const meta = response.meta;

  console.log(message, meta);
}

From the meta and/or message you can make the assertions you want.

There's a full example in the Solana Pay code on how we validate transfers for SOL or SPL tokens

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.