Getting the following error when trying to send a signed transaction with Magic Link.
WalletSignTransactionError: Versioned messages must be deserialized with VersionedMessage.deserialize()
Magic's signTransaction method
async signTransaction<
T extends TransactionOrVersionedTransaction<
this['supportedTransactionVersions']
>,
>(transaction: T): Promise<T> {
try {
if (!this._user) throw new WalletNotConnectedError();
try {
const config = { requireAllSignatures: false, verifySignatures: true };
const signedTransaction = await this._magic?.solana.signTransaction(
transaction,
config,
);
const msg = Buffer.from(
signedTransaction?.rawTransaction as string,
'base64',
);
return Transaction.from(msg) as T;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
} catch (error: any) {
this.emit('error', error);
throw error;
}
}
Doc reference: https://magic.link/docs/blockchains/featured-chains/solana#sign-and-send-transaction
Solution: Update @magic-ext/solana to latest version and handle for versioned txn
async signTransaction<
T extends TransactionOrVersionedTransaction<
this['supportedTransactionVersions']
>,
>(transaction: T): Promise<T> {
try {
if (!this._user) throw new WalletNotConnectedError();
try {
const config = { requireAllSignatures: false, verifySignatures: true };
const signedTransaction = await this._magic?.solana.signTransaction(
transaction,
config,
);
let msg: Uint8Array;
let rawTx: unknown = signedTransaction?.rawTransaction;
if (rawTx instanceof Uint8Array) {
msg = rawTx;
} else if (typeof rawTx === 'string') {
msg = base64.serialize(rawTx);
} else {
throw new Error(`Raw transaction is not a buffer or string`);
}
try {
return Transaction.from(msg) as T;
} catch {
return VersionedTransaction.deserialize(msg) as T;
}
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
} catch (error: any) {
this.emit('error', error);
throw error;
}
}