2

I want to move to VersionedTransaction. But methods like StakeProgram.delegate, StakeProgram.deactivate return Transaction. How to use VersionedTransaction with staking?

1 Answer 1

2

You can put in a PR with the implementations, but essentially you just need to change the inner function. For example, here's how you would do delegate with a versioned transaction:

  static delegate(params: DelegateStakeParams): Transaction {
    const {stakePubkey, authorizedPubkey, votePubkey} = params;

    const type = STAKE_INSTRUCTION_LAYOUTS.Delegate;
    const data = encodeData(type);
    const keys = [
        {pubkey: stakePubkey, isSigner: false, isWritable: true},
        {pubkey: votePubkey, isSigner: false, isWritable: false},
        {pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
        {
          pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
          isSigner: false,
          isWritable: false,
        },
        {pubkey: STAKE_CONFIG_ID, isSigner: false, isWritable: false},
        {pubkey: authorizedPubkey, isSigner: true, isWritable: false},
      ];
          const message = new TransactionMessage({
        payerKey: signer1.publicKey,
        instructions: [
          new TransactionInstruction({
            data,
            keys,
            programId: this.programId,
          }),
        ],
        recentBlockhash: bs58.encode(recentBlockhash),
      });                                                                                     
      return new VersionedTransaction(message.compileToV0Message());
    });
  }

Note that I haven't tested this.

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.