-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add browser wallet support #10823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rplusq
wants to merge
7
commits into
foundry-rs:master
Choose a base branch
from
rplusq:feat/browser-wallet-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mattsse
requested changes
Jun 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks decent,
not opposed to this but what I'm missing from this is some API specs or references.
Thanks for the feedback, @mattsse. Applied. |
a53dda8
to
1f5bcf6
Compare
Implements browser wallet integration (MetaMask, etc.) for Foundry tools, addressing issue foundry-rs#6556. - New `browser` wallet type with HTTP server bridge - Web interface for wallet interaction following Moccasin pattern - Queue-based communication between CLI and browser - Support for multiple wallet types (MetaMask, Rabby, etc.) - `cast send --browser`: Full support for sending transactions - `cast mktx --browser`: Clear error message explaining architectural limitation - `forge create --browser`: Full support for contract deployment - Message signing: Support for personal_sign and eth_signTypedData_v4 - Automatic browser opening when --browser flag is used - Connection state management with proper initialization - Transaction approval flow with user confirmation - Message signing for both personal messages and typed data - Hardware wallet security reminder in UI - Comprehensive error handling and timeout management Browser wallets are architecturally incompatible with forge script's execution model. Forge script requires separate sign/broadcast steps, while browser wallets only support atomic eth_sendTransaction. Users should use forge create for deployments or consider alternative wallet options for scripting. This command creates offline transactions, which browser wallets cannot do. The implementation provides a clear error message directing users to use `cast send` instead. - Uses axum for HTTP server - Follows EIP-1193 standard for wallet interaction - Implements proper async/await patterns for transaction handling - Includes comprehensive test suite for browser wallet functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Changed reqwest in foundry-wallets dev-dependencies to use workspace = true - This ensures it inherits the rustls-tls feature instead of default-tls - Fixes cargo deny error about banned openssl dependency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
92e3a3f
to
f12f07e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Motivation
Browser wallets like MetaMask are widely used in the Ethereum ecosystem. This PR adds native support for browser wallets in Foundry, making it more accessible to developers who prefer using their browser wallets for signing transactions.
Solution
This implementation follows the Moccasin pattern with a local HTTP server that bridges between the CLI and browser wallet:
--browser
flag is used, Foundry starts a local server and opens a browser windowWhat's Implemented
Commands with Full Support
cast send --browser
- Send transactions via browser walletforge create --browser
- Deploy contracts via browser walletcast wallet sign --browser
- Message signing with both personal_sign and eth_signTypedData_v4Commands with Limited/No Support
cast mktx --browser
- Shows clear error (browser wallets can't create offline transactions)forge script --browser
- Not implemented (architectural incompatibility explained below)Architectural Decisions
New Dedicated Crate
Browser wallet functionality has been extracted into a dedicated
foundry-browser-wallet
crate for:Why forge script is not supported
Forge script's execution model is fundamentally incompatible with browser wallets:
eth_sendTransaction
(sign+send together)Users who need browser wallet deployments should use
forge create
instead.Implementation Details
axum
for the HTTP serverAPI Documentation
The browser wallet HTTP API and message types are fully documented in
crates/browser-wallet/README.md
. The API includes:HTTP Endpoints: RESTful API for communication between CLI and browser
/api/heartbeat
- Health check and connection status/api/transaction/pending
- Retrieve pending transactions/api/transaction/response
- Submit transaction results/api/sign/pending
- Retrieve pending signing requests/api/sign/response
- Submit signing results/api/network
- Get network configuration/api/account
- Update wallet connection statusMessage Types: Strongly-typed request/response formats
BrowserTransaction
- Transaction request wrapperSignRequest
- Message signing requestsTransactionResponse
- Transaction execution resultsSignResponse
- Signing operation resultsStandards Compliance:
See the full API reference in the browser-wallet README.
Testing
cargo test -p foundry-browser-wallet
to run browser wallet testsBreaking Changes
None - this is a new feature that doesn't affect existing functionality.
Closes #6556
Files Changed
Refactoring (Browser Wallet Extraction)
crates/browser-wallet/
- New dedicated crate for browser wallet functionalityCargo.toml
- Crate configurationREADME.md
- API documentation and usage guidesrc/lib.rs
- Public API and message typessrc/server.rs
- HTTP server implementationsrc/signer.rs
- Alloy signer trait implementationsrc/state.rs
- Shared state managementsrc/error.rs
- Error typessrc/assets.rs
- Embedded web assetssrc/assets/web/
- Enhanced web interface (HTML, CSS, JS)src/tests.rs
- Unit teststests/integration/
- Comprehensive integration testsUpdates to Existing Files
Cargo.lock
- Updated dependenciesCargo.toml
- Added browser-wallet crate to workspacecrates/cast/src/cmd/send.rs
- Updated to use new browser wallet cratecrates/wallets/Cargo.toml
- Removed browser wallet dependenciescrates/wallets/src/
- Removed browser wallet code (moved to dedicated crate)Testing Instructions
Video Demo
cast wallet sign --browser
demo.on.cast.wallet.sign.--browser.mp4