1

Hello I already read this question

But I don't know how to create the BlockheightBasedTransactionConfirmationStrategy object in JS as in that example TS is used.

I will like to get this code in JS:

const connection = new Connection("YOUR_RPC")
const tx = new Transaction()
const signature = await connection.sendRawTransaction(tx.serialize())

const latestBlockHash = await connection.getLatestBlockhash()
const confirmStrategy: BlockheightBasedTransactionConfirmationStrategy = {
    blockhash: latestBlockHash.blockhash,
    lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
    signature: signature
}
const result = await connection.confirmTransaction(confirmStrategy)

EDIT 1:

I tried:

  const sig = conn.sendRawTransaction(tx.serialize())
  console.log(sig);
  const latestBlockHash = conn.getLatestBlockhash();
  const txConfirmation = conn.confirmTransaction({
        blockhash: latestBlockHash.blockhash,
        lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
        signature: sig,
  });

But got this error:

throw new Error('signature must be base58 encoded: ' + rawSignature);

1 Answer 1

2

You're forgetting the await keywords as they're used in the example you're borrowing from. Failing to include them will make Javascript return a promise rather than waiting to receive the actual value you'd expect the function to return.

0

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.