Wallet Adapter (Legacy)
Direct browser namespace access via window.morsel, window.cookie, and window.solana. For custom integrations and environments where the Wallet Standard is not available.
The legacy adapter exposes Morsel's provider directly on the browser window object, similar to how Phantom and Solana wallets have historically worked. This gives you full, low-level control over the connection lifecycle, signing, and event handling.
When to use this
- Your dApp targets a specific Morsel/Cookie Chain integration without needing multi-wallet support
- You are working in a legacy codebase already using window.solana patterns
- You need raw provider access for custom signing flows
- You are building a browser extension or native app that injects its own provider
Installation
Install the adapter package:
npm install @morsel/adapterOr use it directly without a package by accessing the injected provider from the window object after the user has Morsel installed.
Provider Detection
Morsel injects its provider under three namespaces for maximum compatibility:
function getMorselProvider() {
if ('morsel' in window) return window.morsel;
if ('cookie' in window) return window.cookie;
if ('solana' in window && window.solana.isMorsel) return window.solana;
return null;
}
const provider = getMorselProvider();
if (!provider) {
window.open('https://morselwallet.com/install', '_blank');
}window.addEventListener('load', () => {
const provider = getMorselProvider();
// safe to use
});Connect & Disconnect
Request wallet connection. This triggers the Morsel approval popup for the user.
const provider = window.morsel;
try {
const { publicKey } = await provider.connect();
console.log('Connected:', publicKey.toBase58());
} catch (err) {
console.error(err);
}
await provider.disconnect();Connect silently (only succeeds if already approved):
await provider.connect({ onlyIfTrusted: true });Public Key
const pubkey = provider.publicKey;
console.log(pubkey.toBase58());
console.log(pubkey.toBytes());Sign Message
const message = 'Sign in to MyDapp';
const encodedMessage = new TextEncoder().encode(message);
const { signature } = await provider.signMessage(encodedMessage, 'utf8');
const sigBase58 = bs58.encode(signature);Sign Transaction
import { Transaction, SystemProgram, PublicKey } from '@solana/web3.js';
const tx = new Transaction().add(
SystemProgram.transfer({
fromPubkey: provider.publicKey,
toPubkey: new PublicKey('RECIPIENT_ADDRESS'),
lamports: 1_000_000,
})
);
const signedTx = await provider.signTransaction(tx);
const { signature } = await provider.signAndSendTransaction(tx);For multiple transactions:
const signedTxs = await provider.signAllTransactions([tx1, tx2, tx3]);Events
provider.on('accountChanged', (publicKey) => {
if (publicKey) {
console.log('Switched to:', publicKey.toBase58());
} else {
console.log('Disconnected');
}
});
provider.on('connect', (publicKey) => console.log('Connected:', publicKey.toBase58()));
provider.on('disconnect', () => console.log('Disconnected'));
provider.off('accountChanged', handler);Namespace Reference
| Namespace | Flag | Use case |
|---|---|---|
| window.morsel | .isMorsel === true | Primary Morsel namespace — always prefer this |
| window.cookie | .isCookie === true | Cookie Chain ecosystem alias |
| window.solana | .isMorsel === true | Solana compat — only set if no other Solana wallet is installed |