|
| 1 | +# Create an Alert |
| 2 | + |
| 3 | +Learn how to create an alert to monitor function calls for a contract. |
| 4 | + |
| 5 | +## What you'll learn |
| 6 | + |
| 7 | +- Set up alerts for contract functions |
| 8 | +- Configure email and webhook notifications |
| 9 | +- Monitor contract usage patterns |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- Contracts deployed to Stacks mainnet (or use any public contract) |
| 14 | +- A Hiro Platform account - [Sign up free](https://platform.hiro.so) |
| 15 | + |
| 16 | +## Set up contract monitoring |
| 17 | + |
| 18 | +{% stepper %} |
| 19 | + |
| 20 | +{% step %} |
| 21 | +### Navigate to monitoring |
| 22 | + |
| 23 | +Log into the [Hiro Platform](https://platform.hiro.so) and toggle to the **Monitor** tab. |
| 24 | + |
| 25 | +You can set up alert monitoring for any contracts on mainnet. |
| 26 | +{% endstep %} |
| 27 | + |
| 28 | +{% step %} |
| 29 | +### Add contract for monitoring |
| 30 | + |
| 31 | +Click **Add contract** to open the contract lookup modal. |
| 32 | + |
| 33 | +You have two options: |
| 34 | +- **Manual entry**: Enter the contract principal and contract name |
| 35 | +- **Wallet connection**: Connect your wallet to see your deployment history |
| 36 | + |
| 37 | +All contracts deployed to mainnet are public, so you can monitor any of them regardless of who deployed them. |
| 38 | +{% endstep %} |
| 39 | + |
| 40 | +{% step %} |
| 41 | +### View contract activity |
| 42 | + |
| 43 | +Once added, your contract appears under Contract Monitoring where you can: |
| 44 | +- View transaction history |
| 45 | +- See pending transactions in the mempool |
| 46 | +- Click **Create an alert** to set up specific monitoring |
| 47 | +{% endstep %} |
| 48 | + |
| 49 | +{% step %} |
| 50 | +### Configure custom alerts |
| 51 | + |
| 52 | +Set up alerts for any contract function calls with specific conditions: |
| 53 | + |
| 54 | +- **Function called**: Alert when a particular function is called |
| 55 | +- **With arguments**: Alert only when called with specified argument values |
| 56 | +- **By address**: Alert only when called by a specific wallet address |
| 57 | + |
| 58 | +For example, monitor `set-contract-owner`, transfer/mint/burn functions, or any custom functions you've implemented. |
| 59 | +{% endstep %} |
| 60 | + |
| 61 | +{% step %} |
| 62 | +### Choose notification method |
| 63 | + |
| 64 | +Select how you want to receive alerts: |
| 65 | + |
| 66 | +- **Email notifications**: Receive alerts at your email address |
| 67 | +- **Webhook calls**: Send to your API endpoint for custom workflows |
| 68 | + |
| 69 | +You can enable multiple notification methods for the same alert. |
| 70 | +{% endstep %} |
| 71 | + |
| 72 | +{% endstepper %} |
| 73 | + |
| 74 | +## Alert payload format |
| 75 | + |
| 76 | +Email notifications come from Hiro Platform `<platform@hiro.so>`. |
| 77 | + |
| 78 | +Webhook payloads follow this structure: |
| 79 | + |
| 80 | +{% tabs %} |
| 81 | +{% tab label="JSON" %} |
| 82 | +```json |
| 83 | +{ |
| 84 | + "tx_id": "0xa7f511b3f379efef6fe71d0de57712ed13a89c5b6e24dd049eb2cc9a7c24fcb5", |
| 85 | + "nonce": 5, |
| 86 | + "fee_rate": "250", |
| 87 | + "sender_address": "SP2W9QYAHJNS7YTQY9EK2MSTQGX9E2NDMV766JP9Z", |
| 88 | + "sponsored": false, |
| 89 | + "post_condition_mode": "deny", |
| 90 | + "post_conditions": [ |
| 91 | + { |
| 92 | + "type": "stx", |
| 93 | + "condition_code": "sent_equal_to", |
| 94 | + "amount": "3000000", |
| 95 | + "principal": { |
| 96 | + "type_id": "principal_standard", |
| 97 | + "address": "SP2W9QYAHJNS7YTQY9EK2MSTQGX9E2NDMV766JP9Z" |
| 98 | + } |
| 99 | + } |
| 100 | + ], |
| 101 | + "anchor_mode": "any", |
| 102 | + "tx_status": "pending", |
| 103 | + "receipt_time": 1726104636, |
| 104 | + "receipt_time_iso": "2024-09-12T01:30:36.000Z", |
| 105 | + "tx_type": "contract_call", |
| 106 | + "contract_call": { |
| 107 | + "contract_id": "SPHW0EJK5KPDMK03ZX792EMP0Q5J3A39ZMTVZZCY.sample-contract", |
| 108 | + "function_name": "donate", |
| 109 | + "function_signature": "(define-public (donate (amount uint)))", |
| 110 | + "function_args": [ |
| 111 | + { |
| 112 | + "hex": "0x01000000000000000000000000002dc6c0", |
| 113 | + "repr": "u3000000", |
| 114 | + "name": "amount", |
| 115 | + "type": "uint" |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
| 119 | +} |
| 120 | +``` |
| 121 | +{% endtab %} |
| 122 | + |
| 123 | +{% tab label="TypeScript" %} |
| 124 | +```ts |
| 125 | +interface AlertPayload { |
| 126 | + tx_id: string; |
| 127 | + nonce: number; |
| 128 | + fee_rate: string; |
| 129 | + sender_address: string; |
| 130 | + sponsored: boolean; |
| 131 | + post_condition_mode: string; |
| 132 | + post_conditions: PostCondition[]; |
| 133 | + anchor_mode: string; |
| 134 | + tx_status: string; |
| 135 | + receipt_time: number; |
| 136 | + receipt_time_iso: string; |
| 137 | + tx_type: string; |
| 138 | + contract_call: ContractCall; |
| 139 | +} |
| 140 | + |
| 141 | +interface ContractCall { |
| 142 | + contract_id: string; |
| 143 | + function_name: string; |
| 144 | + function_signature: string; |
| 145 | + function_args: FunctionArg[]; |
| 146 | +} |
| 147 | + |
| 148 | +interface FunctionArg { |
| 149 | + hex: string; |
| 150 | + repr: string; |
| 151 | + name: string; |
| 152 | + type: string; |
| 153 | +} |
| 154 | + |
| 155 | +interface PostCondition { |
| 156 | + type: string; |
| 157 | + condition_code: string; |
| 158 | + amount: string; |
| 159 | + principal: Principal; |
| 160 | +} |
| 161 | + |
| 162 | +interface Principal { |
| 163 | + type_id: string; |
| 164 | + address: string; |
| 165 | +} |
| 166 | +``` |
| 167 | +{% endtab %} |
| 168 | +{% endtabs %} |
| 169 | + |
| 170 | +{% hint style="info" %} |
| 171 | +The `tx_status` will always return "pending" for monitor alerts. Notifications are sent when transactions hit the mempool, not when they're confirmed on the blockchain. |
| 172 | +{% endhint %} |
| 173 | + |
| 174 | +## Next steps |
| 175 | + |
| 176 | +- [Hiro Platform](https://platform.hiro.so): Create and manage new webhooks in the Platform. |
| 177 | +- [Chainhooks](https://docs.hiro.so/tools/chainhooks): Learn about advanced event monitoring with Chainhook. |
0 commit comments