Skip to content

Commit 58752f1

Browse files
baptiste-marchandMontoyaadonesky1jiexi
authored
feat: Solana Wallet Standard (#31705)
## **Description** This PR implements [Solana Wallet Standard](https://github.com/anza-xyz/wallet-standard/) using script injection, enabling users use MetaMask on Solana dApps. The communication between the dApp and MetaMask uses the Multichain API. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31705?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Run `yarn` then `yarn start:flask` 2. If you already have a local Flask extension installed, then first uninstall it from chrome://extensions 3. Install the built flask build by loading `dist/chrome` and setup a Solana account 4. Go to any Solana Wallet Standard compatible app, such as [Wallet Standard Demo](https://anza-xyz.github.io/wallet-adapter/example/) or https://jup.ag/ 5. Connect with MetaMask 6. Try the features proposed by the dApp ## **Screenshots/Recordings** MetaMask icon is the first one (the 2nd being Solflare): ![Screenshot 2025-04-08 at 15 09 48](https://github.com/user-attachments/assets/5d913f75-58da-43cf-9c0b-5e21c01afd0d) Connection modal: ![Screenshot 2025-04-08 at 15 17 28](https://github.com/user-attachments/assets/38822726-607e-4512-ab98-b06458fc184a) When connected: ![Screenshot 2025-04-08 at 15 17 46](https://github.com/user-attachments/assets/61f34af4-f469-402d-ab97-f3c1fc79ac89) ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Christian Montoya <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: jiexi <[email protected]>
1 parent a697813 commit 58752f1

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

app/scripts/inpage.js

+20
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ import log from 'loglevel';
3535
import { v4 as uuid } from 'uuid';
3636
import { WindowPostMessageStream } from '@metamask/post-message-stream';
3737
import { initializeProvider } from '@metamask/providers/initializeInpageProvider';
38+
39+
// this is currently equivalent to process.env.MULTICHAIN_API
40+
// which can't be used for conditional imports
41+
///: BEGIN:ONLY_INCLUDE_IF(build-beta,build-flask)
42+
import {
43+
getMultichainClient,
44+
getDefaultTransport,
45+
} from '@metamask/multichain-api-client';
46+
import { registerSolanaWalletStandard } from '@metamask/solana-wallet-standard';
47+
///: END:ONLY_INCLUDE_IF
48+
3849
import shouldInjectProvider from '../../shared/modules/provider-injection';
3950

4051
// contexts
@@ -67,4 +78,13 @@ if (shouldInjectProvider()) {
6778
rdns: process.env.METAMASK_BUILD_APP_ID,
6879
},
6980
});
81+
82+
// this is currently equivalent to process.env.MULTICHAIN_API
83+
///: BEGIN:ONLY_INCLUDE_IF(build-beta,build-flask)
84+
getMultichainClient({
85+
transport: getDefaultTransport(),
86+
}).then((client) => {
87+
registerSolanaWalletStandard({ client });
88+
});
89+
///: END:ONLY_INCLUDE_IF
7090
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
"@metamask/message-manager": "^12.0.1",
293293
"@metamask/message-signing-snap": "^0.6.0",
294294
"@metamask/metamask-eth-abis": "^3.1.1",
295+
"@metamask/multichain-api-client": "^0.1.1",
295296
"@metamask/multichain-api-middleware": "^0.1.1",
296297
"@metamask/multichain-network-controller": "^0.1.0",
297298
"@metamask/multichain-transactions-controller": "^0.7.2",
@@ -324,6 +325,7 @@
324325
"@metamask/snaps-sdk": "^6.22.0",
325326
"@metamask/snaps-utils": "^9.2.0",
326327
"@metamask/solana-wallet-snap": "^1.18.1",
328+
"@metamask/solana-wallet-standard": "^0.1.1",
327329
"@metamask/transaction-controller": "^54.0.0",
328330
"@metamask/user-operation-controller": "^31.0.0",
329331
"@metamask/utils": "^11.1.0",

yarn.lock

+67
Original file line numberDiff line numberDiff line change
@@ -5776,6 +5776,13 @@ __metadata:
57765776
languageName: node
57775777
linkType: hard
57785778

5779+
"@metamask/multichain-api-client@npm:^0.1.1":
5780+
version: 0.1.1
5781+
resolution: "@metamask/multichain-api-client@npm:0.1.1"
5782+
checksum: 10/85d8e7d20389460269ddd07388dcbfdbceb532df0e21d5184f810f90d4e8817318e717b0f6f716fce6ad7c457d54c476c1e7ac209cbb6b0757cbebd747917568
5783+
languageName: node
5784+
linkType: hard
5785+
57795786
"@metamask/multichain-api-middleware@npm:^0.1.1":
57805787
version: 0.1.1
57815788
resolution: "@metamask/multichain-api-middleware@npm:0.1.1"
@@ -6571,6 +6578,20 @@ __metadata:
65716578
languageName: node
65726579
linkType: hard
65736580

6581+
"@metamask/solana-wallet-standard@npm:^0.1.1":
6582+
version: 0.1.1
6583+
resolution: "@metamask/solana-wallet-standard@npm:0.1.1"
6584+
dependencies:
6585+
"@solana/wallet-standard-chains": "npm:^1.1.1"
6586+
"@solana/wallet-standard-features": "npm:^1.3.0"
6587+
"@wallet-standard/base": "npm:^1.1.0"
6588+
"@wallet-standard/features": "npm:^1.1.0"
6589+
"@wallet-standard/wallet": "npm:^1.1.0"
6590+
bs58: "npm:^6.0.0"
6591+
checksum: 10/06559ac73f590d360c8b8e053bdfde94077558bc861e4bc03dffa6578d939e3774c94957f95488e9394c75efd3bd0533035f1f10da2f5b8dfba2533e16193af4
6592+
languageName: node
6593+
linkType: hard
6594+
65746595
"@metamask/superstruct@npm:^3.0.0, @metamask/superstruct@npm:^3.1.0, @metamask/superstruct@npm:^3.2.1":
65756596
version: 3.2.1
65766597
resolution: "@metamask/superstruct@npm:3.2.1"
@@ -8876,6 +8897,25 @@ __metadata:
88768897
languageName: node
88778898
linkType: hard
88788899

8900+
"@solana/wallet-standard-chains@npm:^1.1.1":
8901+
version: 1.1.1
8902+
resolution: "@solana/wallet-standard-chains@npm:1.1.1"
8903+
dependencies:
8904+
"@wallet-standard/base": "npm:^1.1.0"
8905+
checksum: 10/8903840e721642e1699dc949f7c9e75e2d6f4c26b7e768e871d91d4006731356dea64426c7351381912671887979ef47193fc17cb8b12ba819334f95f83c0ba6
8906+
languageName: node
8907+
linkType: hard
8908+
8909+
"@solana/wallet-standard-features@npm:^1.3.0":
8910+
version: 1.3.0
8911+
resolution: "@solana/wallet-standard-features@npm:1.3.0"
8912+
dependencies:
8913+
"@wallet-standard/base": "npm:^1.1.0"
8914+
"@wallet-standard/features": "npm:^1.1.0"
8915+
checksum: 10/9c4ef26346ef0b602ad4bde7a32e53716b96a427c4f7120571be949efeefa21a2458e9d6ef41bf1be7a1e3f2a45fa631fc4242503a87043d74bb7213c62509c2
8916+
languageName: node
8917+
linkType: hard
8918+
88798919
"@solana/web3.js@npm:^2.0.0":
88808920
version: 2.0.0
88818921
resolution: "@solana/web3.js@npm:2.0.0"
@@ -12500,6 +12540,31 @@ __metadata:
1250012540
languageName: node
1250112541
linkType: hard
1250212542

12543+
"@wallet-standard/base@npm:^1.1.0":
12544+
version: 1.1.0
12545+
resolution: "@wallet-standard/base@npm:1.1.0"
12546+
checksum: 10/11dbb8ed80566265916ab193ad5eab1585d55996781a88039d2bc4480428b1e778901b2dcff3e688dcac7de45e8a9272026f37f07f1e75168caff581906c5079
12547+
languageName: node
12548+
linkType: hard
12549+
12550+
"@wallet-standard/features@npm:^1.1.0":
12551+
version: 1.1.0
12552+
resolution: "@wallet-standard/features@npm:1.1.0"
12553+
dependencies:
12554+
"@wallet-standard/base": "npm:^1.1.0"
12555+
checksum: 10/e046f813ec4bfea172aeb6c11358a962afe8f9a6961453e621d624f89d8b5fc8a44404dacfe18d33be815df6e9117bbf914009f5a9f9ea91ff90a136043fcac8
12556+
languageName: node
12557+
linkType: hard
12558+
12559+
"@wallet-standard/wallet@npm:^1.1.0":
12560+
version: 1.1.0
12561+
resolution: "@wallet-standard/wallet@npm:1.1.0"
12562+
dependencies:
12563+
"@wallet-standard/base": "npm:^1.1.0"
12564+
checksum: 10/b56846709c43b1dee6b44f7a9e15d89a00e4408d3d967eb438f415b42c5c52c4cf33a7b3126d0cf0dc0d78f244755e3d084a05824c1397ce58be169426c5337b
12565+
languageName: node
12566+
linkType: hard
12567+
1250312568
"@webassemblyjs/ast@npm:1.12.1, @webassemblyjs/ast@npm:^1.12.1":
1250412569
version: 1.12.1
1250512570
resolution: "@webassemblyjs/ast@npm:1.12.1"
@@ -27347,6 +27412,7 @@ __metadata:
2734727412
"@metamask/message-manager": "npm:^12.0.1"
2734827413
"@metamask/message-signing-snap": "npm:^0.6.0"
2734927414
"@metamask/metamask-eth-abis": "npm:^3.1.1"
27415+
"@metamask/multichain-api-client": "npm:^0.1.1"
2735027416
"@metamask/multichain-api-middleware": "npm:^0.1.1"
2735127417
"@metamask/multichain-network-controller": "npm:^0.1.0"
2735227418
"@metamask/multichain-transactions-controller": "npm:^0.7.2"
@@ -27381,6 +27447,7 @@ __metadata:
2738127447
"@metamask/snaps-sdk": "npm:^6.22.0"
2738227448
"@metamask/snaps-utils": "npm:^9.2.0"
2738327449
"@metamask/solana-wallet-snap": "npm:^1.18.1"
27450+
"@metamask/solana-wallet-standard": "npm:^0.1.1"
2738427451
"@metamask/test-bundler": "npm:^1.0.0"
2738527452
"@metamask/test-dapp": "npm:9.2.0"
2738627453
"@metamask/test-dapp-multichain": "npm:^0.6.0"

0 commit comments

Comments
 (0)