import{getWalletBySource}from'@subwallet/wallet-connect';import{DotPassportClient,createWidget}from'@dotpassport/sdk';// 1. Get SubWalletconstsubwallet=awaitgetWalletBySource('subwallet-js');// 2. Enable and get accountsawaitsubwallet.enable();constaccounts=awaitsubwallet.getAccounts();constaddress=accounts[0].address;// 3. Use with DotPassportconstclient=newDotPassportClient({apiKey:'your_api_key'});constscores=awaitclient.getScores(address);console.log(`Reputation: ${scores.totalScore}`);
Complete Integration Guide
Step 1: Check for Wallet Installation
Step 2: Connect to Wallet
Step 3: Get User Accounts
Step 4: Subscribe to Account Changes
Step 5: Integrate with DotPassport
Complete React Example
Complete Vanilla JavaScript Example
Error Handling
Working with Multiple Networks
SubWallet supports multiple networks. Here's how to filter accounts by network:
import { getWalletBySource, isWalletInstalled } from '@subwallet/wallet-connect';
async function checkSubWalletInstalled(): Promise<boolean> {
return isWalletInstalled('subwallet-js');
}
// Or check by trying to get the wallet
async function getSubWallet() {
const wallet = await getWalletBySource('subwallet-js');
if (!wallet) {
throw new Error('SubWallet is not installed');
}
return wallet;
}
import { getWalletBySource, Wallet } from '@subwallet/wallet-connect';
async function connectSubWallet(): Promise<Wallet> {
const wallet = await getWalletBySource('subwallet-js');
if (!wallet) {
throw new Error('SubWallet not found. Please install SubWallet extension.');
}
// Enable the wallet - this prompts user for permission
await wallet.enable();
return wallet;
}
import { WalletAccount } from '@subwallet/wallet-connect';
async function getAccounts(wallet: Wallet): Promise<WalletAccount[]> {
const accounts = await wallet.getAccounts();
if (accounts.length === 0) {
throw new Error('No accounts found. Please create an account in SubWallet.');
}
return accounts;
}
// Usage
const wallet = await connectSubWallet();
const accounts = await getAccounts(wallet);
console.log('Available accounts:');
accounts.forEach(acc => {
console.log(`- ${acc.name || 'Account'}: ${acc.address}`);
});