Create Your First Link
Create Your First Link
Section titled “Create Your First Link”Follow these steps to create your first payment-gated link with Gatepay using the createLink
convenience function from the SDK.
1. Initialize the SDK
Section titled “1. Initialize the SDK”import { Gatepay } from "gatepay-sdk"const gatepay = new Gatepay({ apiToken: "your-api-token" })
2. Create a Link with createLink
Section titled “2. Create a Link with createLink”The SDK provides a type-safe createLink
function for convenience:
const link = await gatepay.createLink({ name: "Premium Content", description: "Access to exclusive premium content",
// Resource configuration - what users get after payment resource: { type: "link", data: { url: "https://example.com/premium-content", }, },
// Payment configuration toll: { tollPaymentRequirements: [ { assetNetwork: "base", amount: "1000000", // 1 USDC assetAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", destinationAddress: "0x742d35Cc6634C0532925a3b8D098C6dd9f67e235", }, ], },})
3. Access and Share Your Link
Section titled “3. Access and Share Your Link”- The response includes the link URL (e.g.,
link.url
). - Share this link with your users. They will be prompted to pay before accessing the resource.
4. Add Payment Callbacks (Optional)
Section titled “4. Add Payment Callbacks (Optional)”To receive notifications when payments are completed, you can add actions after creating the link:
// Add a callback action to the linkawait gatepay.links.postLinksByLinkUuidActions({ linkUuid: link.uuid, postLinksByLinkUuidActionsRequest: { type: "callback", data: { url: "https://your-api.com/webhooks/payment-completed/my-ref", method: "POST", }, },})
5. Monitor Payments
Section titled “5. Monitor Payments”You can monitor payments for your link using the SDK:
// Get payments for a specific linkconst payments = await gatepay.links.getLinksByLinkUuidPayments({ linkUuid: link.uuid, limit: 10, page: 1,})
console.log(`Found ${payments.payments?.length} payments`)
See also: