@pulsadev/wallet-connect
v0.1.0
Published
Lightweight wallet connection for EVM dApps — framework agnostic, no API key, EIP-6963 native
Readme
@pulsadev/wallet-connect
Lightweight wallet connection for EVM dApps — framework agnostic, no API key, EIP-6963 native. 8 KB.
Connect browser wallets, WalletConnect, and Coinbase Wallet with one API. Works with React, Vue, Svelte, or vanilla JS.
Features
- EIP-6963 native — automatically discovers all installed browser wallets
- Framework agnostic — no React dependency, works with any framework or vanilla JS
- No API key — core functionality requires zero external services
- WalletConnect v2 — optional adapter for QR code mobile wallet connection
- Coinbase Wallet — optional adapter for Coinbase Wallet SDK
- Event-driven — connect, disconnect, chainChanged, accountsChanged events
- Chain management — switchChain with automatic addChain fallback
- Full wallet API — signMessage, sendTransaction, getBalance
- Zero core dependencies — ~8 KB bundled, ESM + CJS, full TypeScript
Install
npm install @pulsadev/wallet-connectOptional adapters (install only what you need):
# For WalletConnect QR code support
npm install @walletconnect/ethereum-provider
# For Coinbase Wallet support
npm install @coinbase/wallet-sdkQuick Start
Browser wallet (MetaMask, Rainbow, etc.)
import { WalletConnector } from '@pulsadev/wallet-connect'
const connector = new WalletConnector()
// Connect to any available wallet
const wallet = await connector.connect()
console.log(wallet.address) // '0xd8dA...'
console.log(wallet.chainId) // 1
// Or connect to a specific wallet by name or RDNS
const wallet = await connector.connect('MetaMask')
const wallet = await connector.connect('io.metamask')WalletConnect (QR code)
const connector = new WalletConnector()
const wallet = await connector.connectWalletConnect({
projectId: 'your-walletconnect-project-id',
chains: [1, 137, 42161],
showQrModal: true,
metadata: {
name: 'My dApp',
description: 'A cool dApp',
url: 'https://mydapp.com',
icons: ['https://mydapp.com/icon.png'],
},
})Coinbase Wallet
const connector = new WalletConnector()
const wallet = await connector.connectCoinbase({
appName: 'My dApp',
appLogoUrl: 'https://mydapp.com/logo.png',
})API
new WalletConnector(options?)
const connector = new WalletConnector({
chains: [
{ id: 1, name: 'Ethereum' },
{ id: 137, name: 'Polygon', rpcUrl: 'https://polygon-rpc.com' },
],
targetChainId: 1, // auto-switch to this chain on connect
})Connection
// Browser wallet (auto-detect or by name/rdns)
const wallet = await connector.connect()
const wallet = await connector.connect('MetaMask')
const wallet = await connector.connect('io.metamask')
// WalletConnect
const wallet = await connector.connectWalletConnect({ projectId: '...' })
// Coinbase Wallet
const wallet = await connector.connectCoinbase({ appName: '...' })
// Disconnect
connector.disconnect()Wallet Operations
// Get balance
const balance = await connector.getBalance() // bigint (wei)
// Sign a message
const signature = await connector.signMessage('Hello, world!')
// Send a transaction
const txHash = await connector.sendTransaction({
to: '0xA0b8...',
value: '0xde0b6b3a7640000', // 1 ETH
data: '0x',
})
// Switch chain
await connector.switchChain(137) // switches to Polygon
// If chain isn't added, automatically calls wallet_addEthereumChainState
connector.isConnected() // boolean
connector.getStatus() // 'disconnected' | 'connecting' | 'connected'
connector.getAddress() // '0x...' | null
connector.getChainId() // number | null
connector.getWallet() // ConnectedWallet | null
connector.getProvider() // EIP1193Provider | nullWallet Discovery (EIP-6963)
// Get all installed wallets
const wallets = connector.getAvailableWallets()
// [{ name: 'MetaMask', icon: '...', rdns: 'io.metamask', uuid: '...' }, ...]
// Or use standalone functions
import { discoverWallets, getProviderByRdns, getProviderByName } from '@pulsadev/wallet-connect'
const wallets = discoverWallets()
const mmProvider = getProviderByRdns('io.metamask')
const rbProvider = getProviderByName('Rainbow')Events
connector.on('connect', (wallet) => {
console.log('Connected:', wallet.address)
})
connector.on('disconnect', () => {
console.log('Disconnected')
})
connector.on('chainChanged', (chainId) => {
console.log('Chain:', chainId)
})
connector.on('accountsChanged', (accounts) => {
console.log('Accounts:', accounts)
})
connector.on('walletsDiscovered', (wallets) => {
console.log('Found wallets:', wallets.map(w => w.name))
})
connector.on('error', (error) => {
console.error('Error:', error.message)
})
// Remove a handler
connector.off('connect', handler)Why @pulsadev/wallet-connect
| | @pulsadev | wagmi | RainbowKit | web3-onboard | |--|:--:|:--:|:--:|:--:| | Framework agnostic | ✅ | ❌ React | ❌ React | ✅ (abandoned) | | No API key required | ✅ | ✅ | ✅ | ❌ | | EIP-6963 native | ✅ | ✅ | ✅ | ❌ | | WalletConnect v2 | ✅ optional | ✅ | ✅ | ✅ | | Coinbase Wallet | ✅ optional | ✅ | ✅ | ✅ | | Bundle size | ~8 KB | ~100 KB+ | ~100 KB+ | ~50 KB+ | | Core dependencies | 0 | 8+ | 15+ | 10+ | | ESM + CJS | ✅ | ✅ | ❌ | ✅ | | Maintained | ✅ | ✅ | ✅ | ❌ 1yr+ |
License
MIT © Yuto Nakamura
