1

I'm new to Solana development. I'm trying to create a simple token swap application in React js (not using ts). I have issue with confirming the transaction. The "@solana/wallet-adapter-react" is used to sign my transaction.

Here is the sample code:

//using Jupiter Station code for the swap
const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
var transaction = VersionedTransaction.deserialize(swapTransactionBuf);

const signTrans = await wallet.signTransaction(transaction);
const rawTransaction = transaction.serialize()
 
const txid = await connection.sendRawTransaction(rawTransaction, {
  skipPreflight: true,
  maxRetries: 2
});

const latestBlockHash = await connection.getLatestBlockhash();
 
await connection.confirmTransaction({
     blockhash: latestBlockHash.blockhash,
     lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
     signature: txid,
});

Not sure if this is correct - signature: txid,

Essentially, it asks me to sign the transaction and then times out after some time.

Can you please help and steer me to the right direction?

UPD: here is the error to be exact

Signature 1111111111111111111111111111111111111111111111111111111111111111 has expired: block height exceeded.
TransactionExpiredBlockheightExceededError: Signature 1111111111111111111111111111111111111111111111111111111111111111 has expired: block height exceeded.
    at Connection.confirmTransactionUsingBlockHeightExceedanceStrategy (http://localhost:3000/static/js/bundle.js:16151:15)
    at async Connection.confirmTransaction (http://localhost:3000/static/js/bundle.js:15979:14)
    at async handleSwap (http://localhost:3000/static/js/bundle.js:316:7)

UPD2: False alarm, I found a mistake:

   const signTrans = await wallet.signTransaction(transaction);
   const rawTransaction = signTrans.serialize()

I should of serialize signTrans instead of transaction.

I will keep it here in case somebody needs a sample code to sign and send the transcation.

1
  • 1
    Please post your solution as an answer to your own question, then accept your self-answer. Commented Jan 2 at 4:06

1 Answer 1

1
const signTrans = await wallet.signTransaction(transaction);
const rawTransaction = signTrans.serialize()

const txid = await connection.sendRawTransaction(rawTransaction, {
  skipPreflight: true,
  maxRetries: 2
});

I should have serialized signTrans instead of transaction.

I will keep it here in case somebody needs a sample code to sign and send the transaction.

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.