X1 quick start
Add Morsel to an X1 dApp. Install the SDK, set chain="x1", connect, send XNT and read the balance, with React, without React, or with no SDK at all.
X1 is an SVM network whose native coin is XNT. Morsel signs for X1 in the Chrome extension, in its in-app browser on iPhone and Android, and by QR from a desktop browser.
X1 at a glance
| X1 | |
|---|---|
| SDK key | x1 |
| Chain id | solana:4SvBP3omtvcCVWdxq1zBY5cDp4wndjsT |
| Older ids | None |
| Native coin | XNT, 9 decimals |
| Public RPC | https://rpc.mainnet.x1.xyz |
| Explorer | X1 Explorer |
- XNT pays every fee, and the fee follows compute units. On X1 the fee depends on the compute units a transaction asks for, not only on its signatures. A transaction that sets no limit pays for 200,000 units per instruction. Set a limit, as in step 4, and ask
getFeeForMessagefor the real fee. - Few wallets advertise it. The modal lists only wallets that advertise X1's chain id, so on most desktops it shows Morsel and the copy says Morsel supports X1.
For every network side by side, see Networks and chain ids.
1. Install
npm install @morsel-wallet/adapter @solana/web3.jsThe hooks and the connect modal need React 18 or 19, with react-dom. The core works without React.
2. Set the network
import { WalletProvider, WalletModalProvider, WalletModal, ConnectButton } from '@morsel-wallet/adapter';
import { Balance } from './Balance';
import { SendX1 } from './SendX1';
export default function App() {
return (
<WalletProvider chain="x1" autoConnect>
<WalletModalProvider>
<ConnectButton />
<Balance />
<SendX1 to="RECIPIENT_ADDRESS" />
<WalletModal />
</WalletModalProvider>
</WalletProvider>
);
}chain="x1" is your app's network. WalletProvider creates the Morsel adapter, finds the other installed Wallet Standard wallets, and opens a read connection to the public X1 RPC. In production, pass your own endpoint with rpcUrl: a string is for x1 only; for several networks pass a record such as { x1: 'https://…' } or a function of the chain.
3. Connect
<ConnectButton /> opens the modal. Morsel comes first, its row reading Works on X1. Another installed wallet is listed only if it advertises solana:4SvBP3omtvcCVWdxq1zBY5cDp4wndjsT. When none does, a note says Morsel supports X1. and names the installed wallets that don't, yet. Once connected, the button becomes an account chip with the X1 mark.
- Chrome with the Morsel extension: the user approves in the extension.
- Desktop without it: the modal shows a QR code. The user scans it with the Morsel app and approves on their phone.
- Phone browser: Continue in Morsel opens your page inside Morsel's browser, where it connects in one tap.
To open the modal from your own button:
import { useWalletModal } from '@morsel-wallet/adapter';
const { open } = useWalletModal();
<button onClick={() => open()}>Connect</button>;4. Sign and send a transaction
import { ComputeBudgetProgram, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
import { useChain, useWallet } from '@morsel-wallet/adapter';
export function SendX1({ to }: { to: string }) {
const { publicKey, sendTransaction } = useWallet();
const { chain, connection } = useChain();
async function send() {
if (!publicKey) return;
// X1 charges for the compute units you ask for. A plain transfer needs far fewer than 1,000.
const tx = new Transaction()
.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000 }))
.add(
SystemProgram.transfer({
fromPubkey: publicKey,
toPubkey: new PublicKey(to),
lamports: 1_000_000, // 0.001 XNT: 9 decimals
})
);
tx.feePayer = publicKey;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
const signature = await sendTransaction(tx, connection);
console.log(chain.explorerTx(signature));
}
return <button onClick={send} disabled={!publicKey}>Send 0.001 XNT</button>;
}sendTransaction asks Morsel to sign for X1, naming X1's chain id, then sends through connection. Morsel also checks the transaction itself: a blockhash exists only on the network that issued it, so Morsel asks the networks which one it belongs to and shows the user that network before they sign.
- To have the wallet broadcast through its own node instead, call
signAndSendTransaction(tx). It resolves with the signature. A wallet that can't send by itself signs, and the transaction goes out throughuseChain().connection. - To sign without sending, call
signTransaction(tx).
5. Read the balance
import { useWallet, useWalletBalance } from '@morsel-wallet/adapter';
export function Balance() {
const { connected } = useWallet();
const { balance, symbol, loading } = useWalletBalance();
if (!connected) return null;
return <p>{loading ? 'Loading…' : `${balance} ${symbol}`}</p>;
}With no connection passed, useWalletBalance() reads from useChain().connection, so this shows XNT on X1, and symbol is 'XNT'. balance is in whole XNT; lamports is the raw amount. Call refetch() after a send.
Without React
The core works in any framework, or none.
import { ComputeBudgetProgram, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
import { MorselWalletAdapter, connectionFor, svmChain } from '@morsel-wallet/adapter/core';
const chain = svmChain('x1')!;
const connection = connectionFor(chain); // or connectionFor(chain, 'https://your-rpc.example')
const morsel = new MorselWalletAdapter({ chain });
await morsel.connect(); // call it from a click
const lamports = await connection.getBalance(morsel.publicKey!);
console.log(`${lamports / 10 ** chain.native.decimals} ${chain.native.symbol}`);
// X1 charges for the compute units you ask for. A plain transfer needs far fewer than 1,000.
const tx = new Transaction()
.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000 }))
.add(
SystemProgram.transfer({
fromPubkey: morsel.publicKey!,
toPubkey: new PublicKey('RECIPIENT_ADDRESS'),
lamports: 1_000_000, // 0.001 XNT: 9 decimals
})
);
tx.feePayer = morsel.publicKey!;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
const signature = await morsel.sendTransaction(tx, connection);
console.log(chain.explorerTx(signature));svmChain('x1') also accepts the chain id or an older id, and answers null for one it doesn't know. connectionFor throws for an unknown network instead of falling back to Solana. Always pass chain: a MorselWalletAdapter built without one keeps 0.3's behaviour, where the wallet's own network applies.
Without the SDK
Talk to Morsel directly with the chain id. You still build the transaction with @solana/web3.js and an X1 Connection.
The injected provider
In Chrome with the Morsel extension, and inside Morsel's browser on iPhone and Android, Morsel injects window.morsel.
import { Connection, ComputeBudgetProgram, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
const X1 = 'solana:4SvBP3omtvcCVWdxq1zBY5cDp4wndjsT';
const connection = new Connection('https://rpc.mainnet.x1.xyz');
const provider = window.morsel;
await provider.connect();
const lamports = await connection.getBalance(provider.publicKey);
// X1 charges for the compute units you ask for. A plain transfer needs far fewer than 1,000.
const tx = new Transaction()
.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000 }))
.add(
SystemProgram.transfer({
fromPubkey: provider.publicKey,
toPubkey: new PublicKey('RECIPIENT_ADDRESS'),
lamports: 1_000_000, // 0.001 XNT: 9 decimals
})
);
tx.feePayer = provider.publicKey;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
const { signature } = await provider.signAndSendTransaction(tx, { network: X1 });Pass network every time. Without one, window.morsel uses its own network, which is Solana, not X1. An id Morsel doesn't know is refused with 4901; it is never signed as Solana.
Wallet Standard
import { getWallets } from '@wallet-standard/app';
import { Connection, ComputeBudgetProgram, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
import bs58 from 'bs58';
const X1 = 'solana:4SvBP3omtvcCVWdxq1zBY5cDp4wndjsT';
const connection = new Connection('https://rpc.mainnet.x1.xyz');
const morsel = getWallets().get().find((w) => w.name === 'Morsel');
const { accounts: [account] } = await morsel.features['standard:connect'].connect();
const owner = new PublicKey(account.address);
// X1 charges for the compute units you ask for. A plain transfer needs far fewer than 1,000.
const tx = new Transaction()
.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000 }))
.add(
SystemProgram.transfer({
fromPubkey: owner,
toPubkey: new PublicKey('RECIPIENT_ADDRESS'),
lamports: 1_000_000, // 0.001 XNT: 9 decimals
})
);
tx.feePayer = owner;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
const [{ signature }] = await morsel.features['solana:signAndSendTransaction'].signAndSendTransaction({
account,
chain: X1,
transaction: tx.serialize({ requireAllSignatures: false, verifySignatures: false }),
});
console.log(bs58.encode(signature));chain is required: Morsel refuses a send without one, or with an id it doesn't know. Wallet Standard returns the signature as bytes; bs58 turns it into the usual string. See Wallet Standard.
Test networks
| Network | SDK key | Chain id | Public RPC |
|---|---|---|---|
| X1 Testnet | x1-testnet | solana:C7ucgdDEhxLTpXHhWSZxavSVmaNTUJWw | https://rpc.testnet.x1.xyz |
Use chain="x1-testnet" while you build. Morsel knows these ids, so a test transaction is never mistaken for a mainnet one.
Next
- Connect kit: every prop, hook and component, and upgrading from 0.3.
- Provider API: the injected provider in full.
- Deep links: send phone users straight into Morsel's browser.