fairydust makes it simple to add AI-powered micropayments to your app. Users pay with DUST tokens for AI actions, and you handle everything in the browserβno backend required.
Get started in just a few lines of code:
<!-- Include fairydust SDK -->
<script src="https://fairydust.fun/sdk/simple.js"></script>
<link rel="stylesheet" href="https://fairydust.fun/sdk/fairydust.css">
<!-- Add components to your HTML -->
<div id="fairydust-account"></div>
<button id="ai-action" class="fairydust-button" data-cost="5">
Generate with AI
</button>
<script>
// Initialize fairydust
const fairydust = new Fairydust({
appId: 'YOUR-APP-ID'
});
// The SDK automatically enhances your buttons!
document.getElementById('ai-action').addEventListener('click', () => {
// This runs after successful payment
performAIAction();
});
</script>
The Account Component displays the user's connection status and DUST balance. It's the primary way users interact with their fairydust account.
Connected:
Disconnected:
<!-- Automatic initialization -->
<div id="fairydust-account"></div>
<!-- Or create programmatically -->
<script>
fairydust.createAccountComponent('#account-widget', {
onConnect: (user) => console.log('User connected:', user),
onDisconnect: () => console.log('User disconnected'),
onBalanceUpdate: (balance) => console.log('Balance:', balance)
});
</script>
Shows only the fairy emoji (π§ββοΈ). Clicking opens the authentication modal.
Shows fairy emoji and DUST balance. Clicking opens account details with options to buy DUST or disconnect.
Modal shows user's fairyname, large balance display, and action buttons for purchasing DUST or visiting fairydust.fun.
fairydust uses a smooth two-step authentication process that works with both email and phone numbers.
User enters their email or phone number. The system automatically detects the type and validates the format.
User receives a 6-digit code via email or SMS. The form auto-submits when all digits are entered.
The authentication modal shows "Powered by fairydust" and explains that new users get 25 DUST for free when they provide their phone or email.
// Programmatic authentication
fairydust.createAuthenticationComponent('#auth-modal', {
appName: 'Your App Name',
onSuccess: (authResponse) => {
console.log('User authenticated:', authResponse.user);
// Refresh account components
fairydust.refreshAccountComponents();
},
onCancel: () => {
console.log('Authentication cancelled');
}
});
When users need more DUST, they'll have a seamless purchase experience integrated directly into your app.
When a user tries to perform an action without enough DUST, they'll see a purchase modal.
Users will choose from preset DUST packages (e.g., 100 DUST for $1, 500 DUST for $4, 1000 DUST for $7).
Support for credit cards, Apple Pay, Google Pay, and other popular payment methods.
DUST is credited immediately after successful payment, allowing users to continue their action.
// This API is planned for the purchase experience
fairydust.createPurchaseComponent('#purchase-modal', {
packages: [
{ dust: 100, price: 1.00 },
{ dust: 500, price: 4.00 },
{ dust: 1000, price: 7.00 }
],
onSuccess: (purchase) => {
console.log('DUST purchased:', purchase);
// Continue with the original action
},
onCancel: () => {
console.log('Purchase cancelled');
}
});
The main SDK class for creating and managing components.
const fairydust = new Fairydust({
appId: 'your-app-id', // Required: Your registered app ID
apiUrl: 'custom-api-url', // Optional: Custom API endpoint
ledgerUrl: 'custom-ledger-url', // Optional: Custom ledger endpoint
debug: true // Optional: Enable debug logging
});
The SDK dispatches custom events for integration with your app:
// Listen for successful payments
document.addEventListener('fairydust:success', (event) => {
console.log('Payment successful:', event.detail);
});
// Listen for payment errors
document.addEventListener('fairydust:error', (event) => {
console.error('Payment failed:', event.detail);
});
Key CSS classes for styling customization:
Ready to add magical AI payments to your app?
@fairydust/sdk