Ask or search…
K
Links
Comment on page

Solana Account Webhooks (Alpha)

Stream Account Updates and Program Account Updates at The Speed of Solana.

Overview

Note: account webhooks are in alpha mode.
In Solana, everything is an account. Users, exchanges, marketplaces, tokens, and even smart contracts are all accounts. In fact, the Solana blockchain is just a bunch of account interacting with each other via sending transactions. As a result, it is essential to understand how to work with accounts effectively as a Solana developer.
Very often, you'll need to listen for account changes/updates to a list of accounts. Whether you're watching for a balance change, an NFT sale, a token mint — pretty much everything will emit an account update. However, listening to these updates is not easy — you are very likely to miss data, setup complex and costly architectures, and just spend way more time than you need to.
At Helius, we've engineered a tool to help with all of this: account webhooks. Account webhooks let you subscribe to a set of accounts (upto 100k of them!) and/or a set of account owners (programs) and stream all their updates to an endpoint of your choosing!
What's more is that you can modify these webhooks programatically via our APIs. For example: if you're keeping track of all your users for an app and you onboard a new user, you can simply append their address to your webhook with a single edit webhook call.

How to Use Account Webhooks

The easiest way to play with account webhooks is to navigate to our dev portal and create an account webhook through our no-code UI — pictured below.
Helius Dev Portal
You'll also need to of course setup the server that the webhook POSTs the data to. You can easily spin one up in a few seconds on Replit.

Example Code

Here's an example of creating a simple accounts webhook. Make sure to setup your webhook handler separately and also enter valid Solana account addresses.

A Basic Account Webhook

const createWebhook = async () => {
try {
const response = await fetch(
"https://api.helius.xyz/v0/webhooks?api-key=<PASTE YOUR API KEY HERE>",
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
webhookURL: "https://your-webhook-server.com/your-endpoint",
accountAddresses: ["PASTE A SOLANA ACCOUNT ADDRESS HERE"],
accountAddressOwners: [],
webhookType: "account",
}),
}
);
const data = await response.json();
console.log({ data });
} catch (e) {
console.error("error", e);
}
}
createWebhook();
You can also listen to account updates for entire Solana programs! This is very useful for when your programs add/remove accounts dynamically, which most programs do. You do NOT need to call getProgramAccounts repeatedly to keep up with your accounts anymore. Here's an example.

Solana Program Accounts Webhook

const createProgramWebhook = async () => {
try {
const response = await fetch(
"https://api.helius.xyz/v0/webhooks?api-key=<PASTE YOUR API KEY HERE>",
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
webhookURL: "https://your-webhook-server.com/your-endpoint",
accountAddresses: [],
accountAddressOwners: ["PASTE YOUR PROGRAM ADDRESS HERE"],
webhookType: "account",
}),
}
);
const data = await response.json();
console.log({ data });
} catch (e) {
console.error("error", e);
}
}
createProgramWebhook();