js
js copied to clipboard
Support for Versioned Transaction
I want to add a new custom operation to the plugin but in that operation I need to use VersionedTransaction instead of the normal one.
I am able to do this inside the handler as follows:
import { Signer } from '@metaplex-foundation/js';
import { Signer as SolanaSigner } from '@solana/web3.js';
..
export const makeOfferOperationHandler: OperationHandler<MakeOfferOperation> = {
async handle(
operation: MakeOfferOperation,
metaplex: Metaplex,
scope: OperationScope
): Promise<MakeOfferOutput> {
const builder = await makeOfferBuilder(metaplex, operation.input, scope);
const { blockhash, lastValidBlockHeight } = await metaplex.connection.getLatestBlockhash();
const lookupTableAccount = await metaplex.connection
.getAddressLookupTable(operation.input.addressLookupTable)
.then((res) => res.value);
const messageV0 = new TransactionMessage({
payerKey: builder.getFeePayer()!.publicKey,
recentBlockhash: blockhash,
instructions: builder.getInstructions(),
}).compileToV0Message([lookupTableAccount!]);
const transactionV0 = new VersionedTransaction(messageV0);
transactionV0.sign(builder.getSigners() as SolanaSigner[]);
const confirmOptions = makeConfirmOptionsFinalizedOnMainnet(metaplex, scope.confirmOptions);
const signature = await metaplex.connection.sendRawTransaction(
transactionV0.serialize(),
confirmOptions
);
const response = await metaplex
.rpc()
.confirmTransaction(
signature,
{ blockhash, lastValidBlockHeight },
confirmOptions?.commitment
);
const output = {
response,
...builder.getContext(),
};
scope.throwIfCanceled();
return output;
},
};
But getting this error while signing the transaction:
Cannot read properties of undefined (reading 'slice')
(I know type-casting the Signer was a bad idea.) Does anybody know how to solve this issue?