Demo
DisconnectedInteractive XO Connect examples. Note: This demo simulates interactions as it requires a real XO wallet context.
View demo source codeConnect Wallet
Start connection with XO wallet
const accounts = await provider.request({
method: 'eth_requestAccounts'
});Sign Message
Sign a message with personal_sign
const signature = await provider.request({
method: 'personal_sign',
params: [message, account]
});Console
Operation logs
Logs will appear here...
Complete Example
Here's a complete example of how to integrate XO Connect in a React application:
App.tsx
import { useState, useEffect } from 'react';
import { XOConnectProvider } from 'xo-connect';
// Simple setup - no RPC required for connect/sign
const provider = new XOConnectProvider({
debug: true // Optional: enables debug panel
});
function App() {
const [account, setAccount] = useState<string | null>(null);
const [chainId, setChainId] = useState<string>("");
useEffect(() => {
// Listen for events
provider.on('accountsChanged', (accounts) => {
setAccount(accounts[0] || null);
});
provider.on('chainChanged', (newChainId) => {
setChainId(newChainId);
});
}, []);
const connect = async () => {
try {
const accounts = await provider.request({
method: 'eth_requestAccounts'
});
setAccount(accounts[0]);
const chain = await provider.request({
method: 'eth_chainId'
});
setChainId(chain);
} catch (error) {
console.error('Error connecting:', error);
}
};
const signMessage = async () => {
if (!account) return;
const message = "Hello from XO Connect!";
const signature = await provider.request({
method: 'personal_sign',
params: [message, account]
});
console.log('Signature:', signature);
};
return (
<div>
{!account ? (
<button onClick={connect}>Connect Wallet</button>
) : (
<div>
<p>Connected: {account}</p>
<p>Chain: {chainId}</p>
<button onClick={signMessage}>Sign Message</button>
</div>
)}
</div>
);
}