# Transaction Callbacks

{% hint style="success" %}
[<mark style="color:yellow;">Github repo</mark>](https://github.com/Shyft-to/compressed_nft_indexer) for a Merkle tree indexer using Transaction Callbacks.
{% endhint %}

### **Overview**

To create powerful event-driven systems, you need to be able to monitor transactions happening on a blockchain in real-time. You can set up transaction callbacks to watch specific addresses, and whenever a transaction occurs on those addresses, you'll receive a notification to your backend through a POST request. You can also setup filters for different types of transactions you want to be notified about, such as NFT sales, token transfers, NFT burns, and more.

{% hint style="info" %}
You can view the full list of supported on-chain transaction types [<mark style="color:yellow;">here</mark>](https://docs.shyft.to/solana-apis/transactions)<mark style="color:yellow;">.</mark>
{% endhint %}

The best part is that when you receive these callbacks, they come with structured information about the transaction, including its type and detailed data, so you don't need to make additional requests to the blockchain. This makes it easier to build applications that react to specific blockchain activities.

### How to Create Transaction Callbacks

You can create callbacks programmatically through our APIs, Postman or Swagger UI.&#x20;

{% code overflow="wrap" %}

```javascript
const createTransactionCallback = 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": [
                        "ARRAY OF ADDRESSES YOU WANT TO RECEIVE CALLBACKS FOR"
                    ],
                    "callback_url": "YOUR SERVER URL",
                    "type": "CALLBACK", //optional, default is CALLBACK
                    "enable_raw": true, //optional, to receive jsonParsed Solana tx
                    "enable_events": true //optional, to receive anchor events emitted in the tx
                }),
            }
        );
        const data = await response.json();
        console.log(data);
    } catch (e) {
        console.error("callback creation error", e);
    }
}
createTransactionCallback();
```

{% endcode %}

{% content-ref url="../callback-apis" %}
[callback-apis](https://docs.shyft.to/callbacks/callback-apis)
{% endcontent-ref %}

{% embed url="<https://api.shyft.to/sol/api/explore/#/Callbacks/MonitorController_create>" %}

### Transaction Callback Payload

There are 3 major parts in the response structure

* **actions**: The most important section. An array containing structured information about the transaction. it contains **type, source\_protocol** and **info.** The main action summary is present under **info** and will differ based on the transaction type. You can check various actions and their response structures [<mark style="color:yellow;">here</mark>](https://docs.shyft.to/solana-apis/transactions/parsed-transaction-structure#action-response-structures)<mark style="color:yellow;">.</mark>
* **events:**  It is an array of parsed anchor events containing **data** and **name** of events emitted in the transaction. These are automatically parsed if an IDL is provided.
* **raw:** This is the standard Solana jsonParsed transaction&#x20;

```json
{
    "timestamp": "",
    "fee": ,
    "fee_payer": "",
    "signers": [
    ],
    "signatures": [
    ],
    "protocol": {
        "address": "",
        "name": ""
    },
    "type": "",    //Main Transaction type
    "status": "",
    //actions is an array of parsed instructions 
    "actions": [
        {
            "info": {
                //info contains action specific response structure
            },
            "source_protocol": {
                "address":,
                "name":
            },
            "type": "action type"
        }
    ],
    "raw": {
        //jsonParsed Solana transaction
    },
    "events": [
    //Array of anchor events emitted in the transaction
      {
        "data": {
        //Parsed anchor event data if IDL is present
        },
        "name": ""
      }
    ],
    "accounts": [
        {
            "address": ,
            "owner": ,
            "lamports": ,
            "data": ,
        }
    ]
}
```

You can check out different transactions on Translator and see their response structures and understand better.

{% embed url="<https://translator.shyft.to/tx/2pKS8om8Qeqy1hFqTDkLJsjtfsC8pTrEw8Z8RmzQR9moU2U4Wh6ragrSoE4QbaPZaP8bhQXw31prmE1TipMaVWk6>" %}
Token Swap on Jupiter v4
{% endembed %}

{% embed url="<https://translator.shyft.to/tx/4iyidbX7JyzYCvzs9breM1jjPc5CdySyfcRthMuQ7kWt5SrCW3oHCekr5aHuzJRkTPTziQXZsRFQsovJaJnGtAqY>" %}
Compressed NFT sale on Tensor cNFT
{% endembed %}

{% embed url="<https://translator.shyft.to/tx/3PNFreWEccEWa9wfkeHyv45heyT7Z1mQcNnRRM4dPsMo33pGPnyTbKfoRs9pT9RjHZfFFxPcLsNpsLeLvUXexdmN>" %}
NFT Bid on SMB #3091 on ME for&#x20;
{% endembed %}
