Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
Is there any way to get amount(number of token we are sending in transaction) after calling transaction.from() in solana
  var transaction = new web3.Transaction({
    feePayer: new web3.PublicKey(
      '2joML3MhVLPmASMDBYuaMzsFiCtdm3aityWu1pJZ1wg8',
    ),
   
  }).add(
    splToken.Token.createTransferInstruction(
      programId,
      user1TokenAccount.address,
      user2TokenAccount.address,
      user1Wallet.publicKey,
      [],
      1,
    ),
  ); let blockhashObj = await connection.getRecentBlockhash();
  transaction.recentBlockhash = await blockhashObj.blockhash;


  let endocdeTransction = transaction.serialize({
    requireAllSignatures: false,
    verifySignatures: false,
  });

let newconnectionTransction = web3.Transaction.from(newEncodedBuffer);

i want to get amount from newconnectionTransction

i was getting amount in buffer data: <Buffer 03 01 00 00 00 00 00 00 00> which i was unable to decode

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This ability is not exposed for now on the JS side. To do this properly, we would need to expose this struct definition: https://github.com/solana-labs/solana-program-library/blob/e8b7009cc4d8cdd87232ccfc9ce93ab203ada496/token/js/client/token.js#L1519

On your side, for testing, you can copy that struct layout, then call decode on the transaction data to deserialize it. In (untested) code, this would look like:

const decodedTransaction = Transaction.from(encodedTransaction);
const TransferInstructionLayout = BufferLayout.struct([
    BufferLayout.u8('instruction'),
    Layout.uint64('amount'),
]);
const instructionData = TransferInstructionLayout.decode(decodedTransaction.instructions[0].data);
console.log(instructionData.amount);

There may be some steps missing, but this will get you most of the way there! And if you want to add a PR to expose these, then everyone else can use them.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!