Account Callbacks

On-chain account updates, parsed and sent straight to your backend, in real-time.

Overview

In Solana, programs store their data in accounts. There might be some accounts that update quite frequently, instead of continuous polling, you can setup callbacks on them to listen to those changes in real-time.

Also, as a program owner, you need to easily query/filter your accounts data. For this, one needs to poll getProgramAccounts() regularly to create an off-chain replica of your accounts. This is generally very slow and not real-time, leading to discrepancies or out-of-sync data.

With Shyft's Account Callbacks, this becomes super easy. You can register a callback on your program ID (or account addresses your are interested in) and start receiving POST requests to your backend whenever your account data changes.

How to Create Account Callbacks

You can create callbacks programmatically through our APIs, Postman or Swagger UI.

const createTensorCNFTAccountCallback = async () => {
    try {
        const response = await fetch(
            "https://api.shyft.to/sol/v1/callback/create",
            {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'x-api-key': '{ YOUR-API-KEY }'
                },
                body: JSON.stringify({
                    "network": "mainnet-beta", //or devnet
                    "addresses": [
                        "TCMPhJdwDryooaGtiocG1u3xcYbRpiJzb283XfCZsDp"
                    ],
                    "callback_url": "YOUR SERVER URL",
                    "type": "ACCOUNT", //optional, default is CALLBACK
                    "encoding": "PARSED", //optional, default is raw
                    //For parsed encoding to work, please upload IDL to Translator
                }),
            }
        );
        const data = await response.json();
        console.log(data);
    } catch (e) {
        console.error("callback creation error", e);
    }
}
createTensorCNFTAccountCallback ();
📔Callback APIs

Accounts Callback Payload

This is a sample account callback payload for Tensor cNFT program.

You can specify encoding while registering a callback to receive either raw or parsed format.

Upload your IDL on Translator (Shyft's Solana Explorer) to receive parsed account Callbacks.

{
    "account": "TCMPhJdwDryooaGtiocG1u3xcYbRpiJzb283XfCZsDp",
    "accountInfo": {
        "slot": 225433098,
        "pubkey": "2BkYBWCQFjzAvozSMc8AfgKUrUA1tcoVeTbGBLWaFizV8y",
        "lamports": 6355840,
        "owner": "68CzaqYybwkrfskTsyBDg6d2HM6z1bGWk1TABiwAnMyb",
        //Program specific data
        "data": {
            "version": 1,
            "bump": [
                255
            ],
            "owner": "BcVHRoZEuEvei3nDvCVbWpL4mf7G5WnSjXuzPVrNaUF5",
            "assetId": "piccGd7zoyGuE8W147ayMwqJ5bVVRur9WP46icpPPgr",
            "amount": "016694e0",
            "currency": null,
            "expiry": "67141cb8",
            "privateTaker": null,
            "makerBroker": null,
            "raw": "TvJZiqHdsEsB/52sLXMQDxcV5ePWN7WWYX7bqSIJXlZd1IYO6ixCAkoUDDlZ3mxLiKR6T15/Uqb6/4WktYIXun6QbQ43fYc1/B/glGYBAAAAAAC4HBRnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
        }
    }
}

Last updated