Skip to content

Create Your First Link

Follow these steps to create your first payment-gated link with Gatepay using the createLink convenience function from the SDK.

import { Gatepay } from "gatepay-sdk"
const gatepay = new Gatepay({ apiToken: "your-api-token" })

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",
},
],
},
})
  • 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.

To receive notifications when payments are completed, you can add actions after creating the link:

// Add a callback action to the link
await gatepay.links.postLinksByLinkUuidActions({
linkUuid: link.uuid,
postLinksByLinkUuidActionsRequest: {
type: "callback",
data: {
url: "https://your-api.com/webhooks/payment-completed/my-ref",
method: "POST",
},
},
})

You can monitor payments for your link using the SDK:

// Get payments for a specific link
const payments = await gatepay.links.getLinksByLinkUuidPayments({
linkUuid: link.uuid,
limit: 10,
page: 1,
})
console.log(`Found ${payments.payments?.length} payments`)

See also: