Core API
LaserEyesClient
The central component of the LaserEyes core API, orchestrating wallet connections, transactions, and data retrieval through a unified interface.
Initialization
Client Setup
client-initialization.ts
import {
LaserEyesClient,
createStores,
createConfig,
MAINNET
} from '@omnisat/lasereyes-core'
// Create stores for state management
const stores = createStores()
// Create configuration
const config = createConfig({
network: MAINNET,
// Optional: Configure data sources
dataSources: {
maestro: {
apiKey: 'your-maestro-api-key', // Optional for development
},
},
})
// Create and initialize the client
const client = new LaserEyesClient(stores, config)
client.initialize()
// Now you can use the client
console.log('Client initialized')
Wallet Operations
Connection Management
wallet-connection.ts
// Connect to a wallet
await client.connect(UNISAT)
// Check connection status
const isConnected = client.isConnected()
// Get connected address
const address = client.getAddress()
// Disconnect
await client.disconnect()
// Switch wallet provider
await client.switchProvider(XVERSE)
Transaction Operations
transactions.ts
// Send BTC
const txid = await client.sendBTC('bc1q...', 10000)
// Sign a message
const signature = await client.signMessage('Hello')
// Sign a PSBT
const signedPsbt = await client.signPsbt(psbtHex)
// Create an inscription
const txid = await client.inscribe(content, 'text/plain')
Data Retrieval
data-retrieval.ts
// Get balance
const balance = await client.getBalance()
// Get UTXOs
const utxos = await client.getUtxos()
// Get inscriptions
const inscriptions = await client.getInscriptions()
// Get BRC-20 tokens
const tokens = await client.getMetaBalances('brc20')
// Get Runes
const runes = await client.getMetaBalances('runes')
// Estimate fee
const feeRate = await client.estimateFee(1) // For next block
Error Handling
error-handling.ts
try {
await client.connect(UNISAT)
} catch (error) {
if (error.code === 'WALLET_NOT_FOUND') {
console.error('UniSat wallet extension not found')
} else if (error.code === 'USER_REJECTED') {
console.error('User rejected the connection request')
} else {
console.error('Connection failed:', error.message)
}
}
try {
const txid = await client.sendBTC('bc1q...', 10000)
console.log('Transaction sent:', txid)
} catch (error) {
if (error.code === 'INSUFFICIENT_FUNDS') {
console.error('Insufficient funds for this transaction')
} else if (error.code === 'INVALID_ADDRESS') {
console.error('Invalid Bitcoin address')
} else {
console.error('Transaction failed:', error.message)
}
}
Configuration
configuration.ts
const config = createConfig({
// Required: Bitcoin network
network: MAINNET, // or TESTNET, SIGNET, etc.
// Optional: Data source configuration
dataSources: {
maestro: {
apiKey: 'your-maestro-api-key',
},
sandshrew: {
apiKey: 'your-sandshrew-api-key',
},
mempool: {
url: 'https://mempool.space/api',
},
esplora: 'https://blockstream.info/api',
},
// Optional: Wallet options
walletOptions: {
autoConnect: true, // Try to reconnect to last used wallet
defaultProvider: UNISAT, // Default wallet provider
timeout: 30000, // Timeout for wallet operations (ms)
},
// Optional: Debug mode
debug: process.env.NODE_ENV === 'development',
// Optional: Cache options
cacheOptions: {
ttl: 60000, // Cache time-to-live (ms)
maxSize: 100, // Maximum number of items to cache
},
})