JavaScript SDK for integrating Alby OAuth2 Wallet API and Nostr Wallet Connect API. Enables zero-custody bitcoin payments in apps. Connects to lightning network via Nostr Wallet Connect or Alby Wallet API.
git clone https://github.com/getAlby/js-sdk.gitJavaScript SDK for integrating Alby OAuth2 Wallet API and Nostr Wallet Connect API. Enables zero-custody bitcoin payments in apps. Connects to lightning network via Nostr Wallet Connect or Alby Wallet API.
[{"step":"Install the SDK and dependencies","action":"Run `npm install @getalby/sdk @getalby/nostr-wallet-connect` or include the SDK via CDN in your project. Ensure your environment supports modern JavaScript features like ES6 modules.","tip":"Check the SDK documentation for the latest version and compatibility requirements. Use a package manager like npm or yarn for version control."},{"step":"Configure OAuth2 and Nostr Wallet Connect","action":"Register your app with Alby to obtain OAuth2 client credentials. Set up Nostr Wallet Connect by generating a Nostr key pair for your app and sharing the connection URL with users.","tip":"Store OAuth2 client secrets securely, ideally in environment variables. For Nostr Wallet Connect, use a dedicated Nostr relay for better reliability."},{"step":"Implement authentication flow","action":"Redirect users to Alby’s OAuth2 authorization page for wallet connection. Handle the OAuth2 callback to retrieve and store the access token for future API calls.","tip":"Use PKCE (Proof Key for Code Exchange) for enhanced security during OAuth2 authentication. Test the flow in a sandbox environment before deploying to production."},{"step":"Integrate payment functionality","action":"Use the SDK to create invoices, send payments, and subscribe to payment events. Handle errors gracefully and provide real-time feedback to users.","tip":"For complex workflows, consider using the SDK’s async/await pattern to simplify error handling. Log payment events for debugging and analytics."},{"step":"Test and deploy","action":"Test the integration in a staging environment with real Lightning Network transactions. Monitor performance and user feedback post-deployment.","tip":"Use tools like Lightning Network explorers to verify transactions. Implement rate limiting to avoid hitting API quotas."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/getAlby/js-sdkCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Integrate the Alby OAuth2 Wallet API and Nostr Wallet Connect API into a [PLATFORM_NAME] application using the JavaScript SDK. Implement [SPECIFIC_FEATURE] such as sending a Lightning Network payment of [AMOUNT] sats to [RECEIVER_PUBKEY] or [RECEIVER_LNURL]. Ensure the integration follows best practices for zero-custody bitcoin payments and handles OAuth2 authentication securely. Include error handling for failed transactions or connection issues.
Here’s a complete integration example for a web-based bitcoin tipping app called *TipBit* that allows users to send payments via Lightning Network using the Alby OAuth2 Wallet API and Nostr Wallet Connect. The app leverages the `@getalby/js-sdk` library to handle authentication, payment requests, and transaction broadcasting.
**Step 1: Setup and Authentication**
First, we initialize the SDK with the Alby OAuth2 client credentials and Nostr Wallet Connect configuration. The user authenticates via Alby’s OAuth2 flow, granting the app permission to interact with their wallet. We store the access token securely in the browser’s `localStorage` for subsequent requests.
```javascript
import { AlbyWallet } from '@getalby/sdk';
import { NostrWalletConnect } from '@getalby/nostr-wallet-connect';
const albyWallet = new AlbyWallet({
clientId: 'tipbit-app-client-id',
clientSecret: 'tipbit-app-client-secret',
scopes: ['invoices:read', 'invoices:create', 'payments:send']
});
// Redirect user to Alby OAuth2 authorization page
const authUrl = albyWallet.getAuthorizationUrl({
redirectUri: 'https://tipbit.app/auth/callback'
});
window.location.href = authUrl;
```
**Step 2: Nostr Wallet Connect Integration**
Once authenticated, we establish a Nostr Wallet Connect session to interact with the user’s Lightning wallet. This allows us to send payments without custody of the user’s funds. We subscribe to payment events to track transaction status in real-time.
```javascript
const nwc = new NostrWalletConnect({
nostrWalletConnectUrl: 'nostrwalletconnect://...',
appName: 'TipBit'
});
// Listen for payment events
nwc.on('payment', (event) => {
console.log('Payment event:', event);
if (event.status === 'paid') {
alert(`Payment of ${event.amount} sats received!`);
}
});
```
**Step 3: Sending a Payment**
The app now allows users to send a tip of 10,000 sats to a content creator’s Lightning address. The SDK constructs the payment request, signs it with the user’s Nostr key, and broadcasts it to the Lightning Network. We handle potential errors, such as insufficient balance or network issues, and provide user feedback.
```javascript
async function sendTip(lnAddress, amountSats) {
try {
const paymentRequest = await nwc.makeInvoice({
amount: amountSats,
description: 'Tip for great content!'
});
const paymentResult = await nwc.payInvoice({
invoice: paymentRequest.invoice,
amount: amountSats
});
console.log('Payment successful:', paymentResult);
return paymentResult;
} catch (error) {
console.error('Payment failed:', error);
alert('Failed to send tip. Please try again.');
}
}
// Example usage
sendTip('creator@lnaddress.com', 10000);
```
**Step 4: Error Handling and User Feedback**
The integration includes robust error handling to manage scenarios like expired invoices, network failures, or insufficient funds. For example, if the user’s wallet balance is too low, the app displays a friendly message and suggests alternative payment methods, such as connecting a different wallet.
```javascript
nwc.on('error', (error) => {
console.error('NWC Error:', error);
if (error.message.includes('insufficient_balance')) {
alert('Your wallet balance is too low. Please add funds or connect another wallet.');
}
});
```
This implementation ensures that TipBit users can send and receive bitcoin payments in a non-custodial manner, with seamless integration into their existing Lightning wallets. The SDK handles the complexities of OAuth2 authentication, Nostr Wallet Connect, and Lightning Network interactions, allowing developers to focus on building user-friendly features.Cloud ETL platform for non-technical data integration
IronCalc is a spreadsheet engine and ecosystem
Get more done every day with Microsoft Teams – powered by AI
Customer feedback management made simple
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan