4

In @solana/web3.js you'd normally make a transfer SOL transaction with SystemProgram.transfer():

const transferTransaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: fromKeypair.publicKey,
    toPubkey: toKeypair.publicKey,
    lamports: lamportsToSend,
  })
);

await sendAndConfirmTransaction(connection, transferTransaction, [fromKeypair]);

The options for an instruction are defined by TransferParams - right now TransferParams doesn't have any options for priority fees.

How do I send a transaction with priority fees with @solana/web3.js?

1 Answer 1

5

Answering my own question to help others

Priority fees are a seperate instruction added to the transaction. See the Solana Cookbook Priority Fees

From their example:

const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({ 
  units: 1000000 
});

const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({ 
  microLamports: 1 
});

const transaction = new Transaction()
.add(modifyComputeUnits)
.add(addPriorityFee)
.add(
    SystemProgram.transfer({
      fromPubkey: payer.publicKey,
      toPubkey: toAccount,
      lamports: 10000000,
    })

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.