Skip to main content

Custom Webhook

Allows you to setup a Custom GraphQL Alchemy Webhook with help of AWS CDK.

Custom Webhooks use GraphQL queries to define exactly which on-chain data you want to receive, giving you full flexibility over the webhook payload.

Alchemy Documentation About Custom Webhooks: https://docs.alchemy.com/reference/custom-webhook

Usage

import { CustomWebhook, AlchemyCredential, GraphqlQuerySource } from "@kovi-soft/cdk-alchemy-webhooks";

new CustomWebhook(this, "CustomWebhookExample", {
alchemyApiKey: AlchemyCredential.fromPlainText("<your-alchemy-api-key>"),
alchemyNetwork: "eth-mainnet",
alchemyAuthToken: AlchemyCredential.fromPlainText("<your-alchemy-auth-token>"),
alchemyWebhookDestinationUrl: "https://my-domain.com/destination-to-my-server",
alchemyWebhookName: "MyCustomWebhook",
alchemyGraphqlQuery: `{
block {
hash
number
timestamp
transactions {
from {
address
}
createdContract {
address
}
}
}
}`
});

GraphQL Query Source

The alchemyGraphqlQuery prop accepts either a plain string or an IGraphqlQuerySource instance, following the same pattern as AlchemyCredential.

Use GraphqlQuerySource.fromPlainText() to pass the query inline (equivalent to passing a raw string):

alchemyGraphqlQuery: GraphqlQuerySource.fromPlainText(`{
block {
hash
number
}
}`)

Use GraphqlQuerySource.fromSsmParameter() to load the query from AWS SSM Parameter Store at deploy time. The construct automatically grants the Lambda function ssm:GetParameter permission on the specified parameter:

import { CustomWebhook, AlchemyCredential, GraphqlQuerySource } from "@kovi-soft/cdk-alchemy-webhooks";

new CustomWebhook(this, "CustomWebhookFromSsm", {
alchemyApiKey: AlchemyCredential.fromSsmParameter("/alchemy/api-key"),
alchemyNetwork: "eth-mainnet",
alchemyAuthToken: AlchemyCredential.fromSsmParameter("/alchemy/auth-token"),
alchemyWebhookDestinationUrl: "https://my-domain.com/destination-to-my-server",
alchemyWebhookName: "MyCustomWebhook",
alchemyGraphqlQuery: GraphqlQuerySource.fromSsmParameter("/my/graphql-query")
});

Props

PropTypeRequiredDescription
alchemyApiKeystring | IAlchemyCredentialYesAlchemy API key
alchemyNetworkNetwork | stringYesTarget blockchain network
alchemyAuthTokenstring | IAlchemyCredentialYesAlchemy auth token
alchemyWebhookDestinationUrlstringYesURL to receive webhook events
alchemyGraphqlQuerystring | IGraphqlQuerySourceYesGraphQL query defining the webhook payload
alchemyWebhookNamestringNoOptional name for the webhook