Hey @justin_shocknet, I'm trying to add CLINK as an option (along with NWC and lighting address) to a website I'm building. I tried the following snippet but was unable to generate an invoice.
import { ClinkSDK, NofferData } from '@shocknet/clink-sdk';
import { generatePrivateKey } from 'nostr-tools';
const sdk = new ClinkSDK({
privateKey: generatePrivateKey(), // Uint8Array
relays: ['wss://relay.example.com'],
toPubKey: '<receiver_pubkey_hex>',
});
const request: NofferData = {
offer: 'my_offer_id',
amount_sats: 1000, // sats
description: 'coffee for bob', // optional, max 100 chars
expires_in_seconds: 3600, // optional
payer_data: { name: 'Alice' },
};
const receiptCallback = (recepit) => {
console.log("got receipt", recepit)
}
sdk.Noffer(request, receiptCallback).then(response => {
if ('bolt11' in response) {
console.log('Invoice:', response.bolt11);
} else {
console.error('Error:', response.error);
}
});
Here are some console logs if it helps.
[ClinkSDK] Sending request: kind=21001, eventId=0086c14baba41b85e9eb20a331d9ec36aca1cef3ad53b9e8b69ebecc04da28f2, toPub=76ed45f00cea7bac59d8d0b7d204848f5319d7b96c140ffb6fcbaaab0a13d44e, relays=wss://strfry.shock.network, timeout=30s
[ClinkSDK] Request published to 1 relays, waiting for response...
[ClinkSDK] Setting up subscription with filter: {
"since": 1764350705,
"kinds": [
21001
],
"#p": [
"625f85da40c7748b7bb39cc557f13a15611d0b1cef6e886e038566d8d1f5c9fd"
],
"#e": [
"0086c14baba41b85e9eb20a331d9ec36aca1cef3ad53b9e8b69ebecc04da28f2"
]
}
[ClinkSDK] Subscription established for eventId=0086c14baba41b85e9eb20a331d9ec36aca1cef3ad53b9e8b69ebecc04da28f2
[ClinkSDK] End of stored events received for eventId=0086c14baba41b85e9eb20a331d9ec36aca1cef3ad53b9e8b69ebecc04da28f2
[ClinkSDK] Timeout after 30s - no response received for kind=21001, eventId=0086c14baba41b85e9eb20a331d9ec36aca1cef3ad53b9e8b69ebecc04da28f2
[ClinkSDK] Closing subscription for eventId=0086c14baba41b85e9eb20a331d9ec36aca1cef3ad53b9e8b69ebecc04da28f2
I decoded the noffer string from my Shockwallet app and used those values for relays and toPubkey in the sdk constructor.
Let me know if I'm missing something. TIA