Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda