2

I use @solana/web3.js and would like to set a feepayer for a normal sol transaction. When I use the new Transaction constructor it says it's deprecated but I can't find another way to do it. can anyone send me some up-to-date methods because I can't find any?

1 Answer 1

2

You can set it using the non-deprecated constructor, which takes as input TransactionBlockhashCtor with shape:

{
  blockhash: Blockhash,
  feePayer?: PublicKey | null,
  lastValidBlockHeight: number,
  signatures?: SignaturePubkeyPair[]
}

Note that connection.getLatestBlockhash returns both blockhash and lastValidBlockHeight.

If you have a Transaction object (created by that constructor, or the deprecated one, or whatever else), you can also just set transaction.feePayer = somePublicKey to set that field at any point.

4
  • Thank you! I have one more question. Where do I verify that I am able to pay the transaction fee? Because with only the public key you can't do anything. Do I set it when I sendAndConfirmTransaction at the Signer array?
    – Noah
    Commented Sep 8, 2022 at 9:00
  • 1
    Yep, it'll need to be a signer of the transaction to be the fee payer, at the point that the transaction is broadcast. There's different ways to do that depending how you want to sign it. You might want to use sendTransaction from wallet-adapter to use the browser wallet, or you might want to add it as a signer in sendAndConfirmTransaction as you said if you already have the private key.
    – Callum M
    Commented Sep 8, 2022 at 9:12
  • If I set a different feepayer than the sender, the fee is double the price. Why is that?
    – Noah
    Commented Sep 8, 2022 at 9:52
  • IIRC the fee is per signer, so if you have 2 signers you'll pay twice the fee
    – Callum M
    Commented Sep 8, 2022 at 9:57

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.