Skip to content

Commit 8172bf9

Browse files
authored
Merge pull request #652 from magiclabs/jayhwang-sc-89181-solana-versioned-transactions-support
Add support for versioned transaction in Solana
2 parents 61e5fe0 + a4b6f5a commit 8172bf9

File tree

3 files changed

+294
-75
lines changed

3 files changed

+294
-75
lines changed

packages/@magic-ext/solana/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"types": "./dist/types/index.d.ts",
1919
"jsdelivr": "./dist/extension.js",
2020
"exports": {
21+
"types": "./dist/types/index.d.ts",
2122
"import": "./dist/es/index.mjs",
2223
"require": "./dist/cjs/index.js"
2324
},
@@ -28,5 +29,11 @@
2829
},
2930
"devDependencies": {
3031
"@magic-sdk/commons": "^17.1.1"
32+
},
33+
"dependencies": {
34+
"@solana/web3.js": "^1.87.2"
35+
},
36+
"peerDependencies": {
37+
"@solana/web3.js": "^1.87.2"
3138
}
3239
}

packages/@magic-ext/solana/src/index.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Extension } from '@magic-sdk/commons';
22

33
/* eslint-disable no-param-reassign, array-callback-return */
4+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
45
import { SolanaConfig, SolanaPayloadMethod, SerializeConfig } from './type';
56

67
export class SolanaExtension extends Extension.Internal<'solana', any> {
@@ -16,31 +17,18 @@ export class SolanaExtension extends Extension.Internal<'solana', any> {
1617
};
1718
}
1819

19-
public signTransaction = (transaction: any, serializeConfig?: SerializeConfig) => {
20-
const { instructions } = transaction;
21-
22-
const magicInstructions = instructions.map((i: any) => {
23-
return {
24-
...i,
25-
keys: i.keys.map((k: any) => {
26-
return { ...k, pubkey: k.pubkey.toBase58() };
27-
}),
28-
programId: i.programId.toBase58(),
29-
};
30-
});
31-
32-
const params = {
33-
feePayer: transaction.feePayer.toBase58(),
34-
instructions: magicInstructions,
35-
recentBlockhash: transaction.recentBlockhash,
36-
serializeConfig,
37-
};
38-
20+
public signTransaction = (transaction: Transaction | VersionedTransaction) => {
3921
return this.request({
4022
id: 42,
4123
jsonrpc: '2.0',
4224
method: SolanaPayloadMethod.SignTransaction,
43-
params,
25+
params: {
26+
type: transaction instanceof Transaction ? 'legacy' : 0,
27+
serialized: transaction.serialize({
28+
requireAllSignatures: false,
29+
verifySignatures: false,
30+
}),
31+
},
4432
});
4533
};
4634

0 commit comments

Comments
 (0)