Introduction
The SubWallet Extension provides a comprehensive JavaScript API that allows decentralized applications (dApps) to interact with user accounts and request transaction signatures. This API is based on the Polkadot.js extension interface with SubWallet-specific enhancements.Package Information
The DApp integration API is provided through the@subwallet/extension-dapp package.
Core Concepts
Extension Injection
SubWallet injects itself into the browser’swindow.injectedWeb3 object, making it available to all dApps. The extension must be enabled before any other operations can be performed.
Account Types
SubWallet supports multiple account types:- Substrate accounts: Standard Polkadot/Kusama accounts
- Ethereum accounts: EVM-compatible accounts
- Bitcoin accounts: Available through
window.SubWalletBitcoin - Cardano accounts: Available through
window.cardano.subwallet
Authentication Options
When enabling the extension, you can specify which account types your dApp requires:substrate: Only Substrate accountsevm: Only EVM accountsboth: Both Substrate and EVM accounts
Quick Start
Here’s a minimal example to get started:API Overview
The SubWallet DApp API provides the following main functions:Initialization
web3Enable()- Enable extension access for your dAppisWeb3Injected- Check if any extension is injected
Account Management
web3Accounts()- Get all available accountsweb3AccountsSubscribe()- Subscribe to account changesweb3FromAddress()- Get extension instance for a specific addressweb3FromSource()- Get extension instance for a specific source
Signing Operations
- Transaction signing via the
signerinterface - Message signing via
signRaw()
Events & Subscriptions
- Account change subscriptions
- Extension initialization events
TypeScript Support
The package includes full TypeScript definitions. Key types include:Error Handling
All API functions may throw errors. Always wrap calls in try-catch blocks:Common Errors
- “web3Enable(originName) needs to be called before…” - You must call
web3Enable()before using other API functions - “Unable to find injected…” - The requested account or extension source was not found
- “No extension found” - No wallet extension is installed in the browser
Browser Compatibility
SubWallet Extension is compatible with:- Chrome/Chromium-based browsers
- Firefox
- Brave
- Edge
Next Steps
Enable Extension
Learn how to enable SubWallet in your dApp
Manage Accounts
Retrieve and manage user accounts
Sign Transactions
Request transaction signatures from users
Handle Events
Subscribe to account and extension events