@omnisat/lasereyes-core
is a framework-agnostic library designed to provide Bitcoin wallet integration for dApps. It abstracts wallet-specific interactions and offers a unified interface, enabling developers to interact with various Bitcoin wallets seamlessly.
This package is not tied to any specific framework and can be used in any TypeScript or JavaScript environment.
# NPM
npm install @omnisat/lasereyes-core
# Yarn
yarn add @omnisat/lasereyes-core
# PNPM
pnpm install @omnisat/lasereyes-core
# Bun
bun install @omnisat/lasereyes-core
The LaserEyesClient
is the main entry point for the library. It manages wallet connections, handles user authentication, and facilitates interactions with Bitcoin wallets.
Each supported Bitcoin wallet is implemented through a WalletProvider
class. These providers handle the communication between your application and the specific wallet's API.
LaserEyes Core supports the following Bitcoin wallets:
- Leather
- Magic Eden
- OKX
- OP_NET
- Orange
- Oyl
- Phantom
- Sparrow
- UniSat
- Wizz
- Xverse
LaserEyes Core supports multiple Bitcoin networks:
- mainnet
- testnet3
- testnet4
- fractal
- fractal testnet
- signet
import { LaserEyesClient, createStores, createConfig, XVERSE } from '@omnisat/lasereyes-core';
// Create stores for state management
const stores = createStores();
// Optional: Create configuration with network setting
const config = createConfig({ network: 'mainnet' });
// Initialize the client
const client = new LaserEyesClient(stores, config);
client.initialize();
// Connect to a wallet (e.g., Xverse)
client.connect(XVERSE).then(() => {
console.log('Connected to Xverse wallet');
});
// Connect to a wallet
await client.connect(XVERSE);
// Request wallet accounts
const accounts = await client.requestAccounts();
console.log('Accounts:', accounts);
// Get wallet balance
const balance = await client.getBalance();
console.log('Balance:', balance.toString());
// Send Bitcoin
const txId = await client.sendBTC('recipient-address', 10000); // 10,000 satoshis
console.log('Transaction ID:', txId);
// Sign a message
const signature = await client.signMessage('Hello, LaserEyes!');
console.log('Signature:', signature);
// Disconnect
client.disconnect();
constructor(
stores: {
readonly $store: MapStore<LaserEyesStoreType>
readonly $network: WritableAtom<NetworkType>
},
readonly config?: Config
)
-
$store
: A MapStore that tracks the application state -
$network
: A WritableAtom that tracks the current network type
Initializes the client and checks for wallet providers.
client.initialize();
Connects to the specified wallet provider.
await client.connect(XVERSE);
Disconnects from the currently connected wallet provider.
client.disconnect();
Requests accounts from the connected wallet provider.
const accounts = await client.requestAccounts();
Gets the current network for the connected wallet provider.
const network = await client.getNetwork();
Switches the network for the connected wallet provider.
await client.switchNetwork('testnet');
Gets the balance of the connected wallet.
const balance = await client.getBalance();
Sends Bitcoin to the specified address.
const txId = await client.sendBTC('recipientAddress', 10000); // 10,000 satoshis
Signs a message with the connected wallet.
const signature = await client.signMessage('Hello, LaserEyes!');
Signs a Partially Signed Bitcoin Transaction (PSBT).
const result = await client.signPsbt(psbtHex, true, false);
Pushes a PSBT to the network.
const txId = await client.pushPsbt(psbtHex);
Gets the public key from the connected wallet.
const publicKey = await client.getPublicKey();
Gets inscriptions (NFTs) associated with the connected wallet.
const inscriptions = await client.getInscriptions();
Inscribes content onto the blockchain.
import { TEXT_PLAIN } from '@omnisat/lasereyes-core';
const contentBase64 = Buffer.from('Hello, LaserEyes!').toString('base64');
const txId = await client.inscribe(contentBase64, TEXT_PLAIN);
Sends assets using the specified protocol.
import { BTC } from '@omnisat/lasereyes-core';
const txId = await client.send(BTC, {
fromAddress: 'senderAddress',
toAddress: 'recipientAddress',
amount: 10000,
network: 'mainnet'
});
Disposes of all wallet providers.
client.dispose();
import {
LEATHER,
MAGIC_EDEN,
OKX,
OP_NET,
ORANGE,
OYL,
PHANTOM,
SPARROW,
UNISAT,
WIZZ,
XVERSE
} from '@omnisat/lasereyes-core';
import {
MAINNET,
TESTNET,
TESTNET4,
SIGNET,
FRACTAL_MAINNET,
FRACTAL_TESTNET
} from '@omnisat/lasereyes-core';
import {
TEXT_HTML,
TEXT_PLAIN,
APPLICATION_JSON,
IMAGE_JPEG,
IMAGE_PNG
// ... many more available
} from '@omnisat/lasereyes-core';
import {
BTC,
BRC20,
RUNES,
ALKANES
} from '@omnisat/lasereyes-core';
LaserEyes Core throws appropriate errors when operations fail. Always wrap your wallet interactions in try-catch blocks:
try {
await client.connect(XVERSE);
const balance = await client.getBalance();
console.log('Balance:', balance.toString());
} catch (error) {
console.error('Wallet error:', error);
}
// Sign a PSBT
const { signedPsbtHex, signedPsbtBase64, txId } = await client.signPsbt(
psbtHex, // PSBT in hex format
true, // finalize
true // broadcast
);
// If not broadcasting immediately, push the PSBT later
if (!txId) {
const broadcastTxId = await client.pushPsbt(signedPsbtHex);
console.log('Broadcast transaction ID:', broadcastTxId);
}
// Create an inscription
const content = Buffer.from('Hello, Ordinals!').toString('base64');
const txId = await client.inscribe(content, TEXT_PLAIN);
console.log('Inscription transaction ID:', txId);
// Get all inscriptions for the connected wallet
const inscriptions = await client.getInscriptions();
console.log('Inscriptions:', inscriptions);
import { RUNES } from '@omnisat/lasereyes-core';
// Send runes
const txId = await client.send(RUNES, {
runeId: '123456:78',
fromAddress: 'senderAddress',
toAddress: 'recipientAddress',
amount: 100,
network: 'mainnet'
});
// Get rune balances
const runeBalances = await client.getMetaBalances(RUNES);
-
Initialize once: Create a single instance of
LaserEyesClient
and reuse it. - Handle errors: Wrap all wallet interactions in try-catch blocks.
-
Clean up: Call
dispose()
when you're done with the client to free resources. - Network awareness: Check the current network before performing transactions.
- User confirmation: Always get user confirmation before signing transactions.
- Check if the wallet extension is installed
- Verify the wallet is unlocked
- Check the console for specific error messages
- Confirm sufficient balance
- Check network configuration
- Verify recipient address format
- Ensure the wallet has the appropriate permissions
- Check if the message format is correct
import { LaserEyesClient, createStores, UNISAT } from '@omnisat/lasereyes-core';
const client = new LaserEyesClient(createStores());
client.initialize();
document.getElementById('connect-button').addEventListener('click', async () => {
try {
await client.connect(UNISAT);
const address = client.$store.get().address;
document.getElementById('address-display').textContent = address;
} catch (error) {
console.error('Connection error:', error);
}
});
document.getElementById('send-button').addEventListener('click', async () => {
const recipient = document.getElementById('recipient').value;
const amountSats = parseInt(document.getElementById('amount').value);
try {
const txId = await client.sendBTC(recipient, amountSats);
document.getElementById('tx-display').textContent = `Transaction sent: ${txId}`;
} catch (error) {
console.error('Send error:', error);
}
});
document.getElementById('inscribe-button').addEventListener('click', async () => {
const text = document.getElementById('inscription-text').value;
const contentBase64 = Buffer.from(text).toString('base64');
try {
const txId = await client.inscribe(contentBase64, TEXT_PLAIN);
document.getElementById('inscription-display').textContent = `Inscription created: ${txId}`;
} catch (error) {
console.error('Inscription error:', error);
}
});
Contributions to LaserEyes Core are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
LaserEyes Core is MIT licensed.
wooooo