Working with Inscriptions
Learn how to fetch, manage, and send Bitcoin Ordinal inscriptions using LaserEyes.
LaserEyes provides comprehensive support for Bitcoin Ordinal inscriptions, allowing you to easily fetch, display, and transfer inscriptions across different Bitcoin wallets.
Key Features
Fetch Inscriptions
Retrieve inscriptions for any Bitcoin address with pagination support.
Send Inscriptions
Securely transfer inscriptions between addresses with built-in PSBT support.
Rich Metadata
Access comprehensive inscription metadata including content type, preview, and transaction details.
Safe Transfers
Built-in safety checks and validations for secure inscription transfers.
The Inscription Type
Inscription Interface
type Inscription = {
id: string; // Unique identifier
inscriptionId: string; // Ordinal inscription ID
content: string; // Content data
number: number; // Inscription number
address: string; // Current owner address
contentType: string; // MIME type of content
output: string; // UTXO containing the inscription
location: string; // Location within the UTXO
genesisTransaction: string; // Transaction where inscription was created
height: number; // Block height of inscription
preview: string; // Preview URL if available
outputValue: number; // Value of the UTXO
offset?: number; // Offset within the UTXO
}
Fetching Inscriptions
Example
import { useLaserEyes } from '@omnisat/lasereyes-react'
import { useState, useEffect } from 'react'
function InscriptionsList() {
const { getInscriptions } = useLaserEyes()
const [inscriptions, setInscriptions] = useState([])
useEffect(() => {
const fetchInscriptions = async () => {
// Fetch first 20 inscriptions
const results = await getInscriptions(0, 20)
setInscriptions(results)
}
fetchInscriptions()
}, [])
return (
<div>
{inscriptions.map(inscription => (
<div key={inscription.id}>
<img
src={inscription.preview}
alt={`Inscription #${inscription.number}`}
/>
<p>Number: {inscription.number}</p>
<p>Content Type: {inscription.contentType}</p>
</div>
))}
</div>
)
}
Sending Inscriptions
Example
import { useLaserEyes } from '@omnisat/lasereyes-react'
import { useState } from 'react'
function SendInscription() {
const { sendInscriptions } = useLaserEyes()
const [sending, setSending] = useState(false)
const handleSend = async () => {
try {
setSending(true)
// Send multiple inscriptions to an address
const txId = await sendInscriptions(
['inscription1', 'inscription2'],
'bc1p...' // Recipient address
)
console.log('Transaction ID:', txId)
} catch (error) {
console.error('Failed to send:', error)
} finally {
setSending(false)
}
}
return (
<button
onClick={handleSend}
disabled={sending}
>
{sending ? 'Sending...' : 'Send Inscriptions'}
</button>
)
}
Best Practices
1. Pagination
Always implement pagination when fetching inscriptions to improve performance and user experience. The getInscriptions method accepts offset and limit parameters.
2. Error Handling
Implement proper error handling for both fetching and sending inscriptions. Network issues or wallet rejections should be handled gracefully.
3. Loading States
Show appropriate loading states during inscription operations. Both fetching and sending can take time to complete.
4. Validation
Always validate inscription IDs and recipient addresses before attempting transfers. The sendInscriptions method will throw if inscriptions are not found.