Search documentation

Alerting Examples

General remarks

Currently, it is not possible to limit the number of (email) alerts, but it is on the roadmap for the future. Currently, the email alerts are rate-limited in the way that all alerts that are received within a timeframe of 120s are combined in one email. We do that due to not getting black-listed as being a spammer.
However, as long as e.g. a balance threshold has been reached, the alert will be repeatedly fired, so you’ll get an email every few minutes.
If you are having a use case where this is a problem, do reach out to support@anyblockanalytics.com so that we can try to mitigate it and get your take on the best way how to implement the new functionality.

Monitor ERC-20 Token Movements in and out of a Wallet Address via Email

First of all, the configuration for an alert is completely build in a generic way and thus you need in case for defining a target in the targetMap an operator. Each target is a comparison using an operator. Deeper structures like the “args” of an ethereum “event” or “call” must get inspected, therefore you need the “inspect” operator so our alerting process knows to step down in that structure to do more comparisons.

In order to get alerted for the events you want to know, you need to know the ABI of the contract (which emits the events) you are trying to monitor.

If you look for example at the EWTB and you would pick the Transfer event, then the parameters are “from”, “to” and “value”.

Here is an example for you to customize:

{
    "alerts":[
        {
            "type":"Email",
            "payload":[
                {
                    "fieldName":"transactionHash",
                    "fieldType":"Field"
                }
            ],
            "parameters":{
                "recipients":[
                    "YOUR-EMAIL@ADDRESS.COM"
                ]
            }
        }
    ],
    "targetMap":[
        {
            "name":"address",
            "value":"0x178c820f862B14f316509ec36b13123DA19A6054",
            "operator":"Equals (ignore case)"
        },
        {
            "name":"args",
            "operator":"Inspect",
            "operatorParameters":[
                {
                    "name":"value",
                    "value":"1",
                    "operator":"Greater"
                },
                {
                    "operator":"Or",
                    "operatorParameters":[
                        {
                            "name":"from",
                            "value":[
                                "0xYOUR-WALLET-ADDRESS-HERE",
                                "0xYOUR-2nd-WALLET-ADDRESS-HERE"
                            ],
                            "operator":"Equals any (ignore case)"
                        },
                        {
                            "name":"to",
                            "value":[
                                "0xYOUR-WALLET-ADDRESS-HERE",
                                "0xYOUR-2nd-WALLET-ADDRESS-HERE"
                            ],
                            "operator":"Equals any (ignore case)"
                        }
                    ]
                }
            ]
        }
    ],
    "targetType":"Event"
}

Some notes on this example:

  • the email addresses must be enclosed in the “recipients” array
  • it is recommended for address comparisons using the “ignore case” variant of equals because some addresses might be written in checksum case and you want all variants of cases to be matched here
  • you should determine a meaningful value for the actual “value” in the transfer to get triggered (in the example we just put “1”)
  • the OR clause helps us to catch both cases: “from” and “to”
  • the “from” and “to” comparisons have an array as the value so you can monitor several addresses at once

Monitoring the Gas balance of a smart contract

{
    "alerts": [
        {
            "type": "Email",
            "payload": [
                {
                    "fieldName": "transactionHash",
                    "fieldType": "Field"
                }
            ],
            "parameters": {
                "recipients": [
                    "email1@gmail.com",
                    "email2@gmail.com"
                ]
            }
        }
    ],
    "targetMap": [
        {
            "name": "address",
            "value": "0xAddress",
            "operator": "Equals (ignore case)"
        },
        {
            "name": "balance",
            "value": "0xHexValueOfWei",
            "operator": "Less or Equal"
        }
    ],
    "targetType": "Balance"
}

Some notes on this example:

  • see the notes from the token transfer example
  • the balance value 0xHEX-VALUE-OF-WEI must be the Wei balance notated in hex, e.g. 0.5 ETH would be 0xB1A2BC2EC50000 (0,5 * 10^18)

 

Kovan DAI Transfer

{
    "alerts":[
        {
            "type":"Webhook (POST)",
            "payload":[
                {
                    "fieldName":"transactionHash",
                    "fieldType":"Field"
                },
                {
                    "fieldName":"args",
                    "fieldType":"Sub Field",
                    "subPayloads":[
                        {
                            "fieldName":"dst",
                            "fieldType":"Field"
                        },
                        {
                            "fieldName":"src",
                            "fieldType":"Field"
                        },
                        {
                            "fieldName":"wad",
                            "fieldType":"Field"
                        }
                    ]
                }
            ],
            "parameters":{
                "url":"https://mywebhook.example/{transactionHash}/{args#src}"
            }
        }
    ],
    "targetMap":[
        {
            "name":"address",
            "value":"0xC4375B7De8af5a38a93548eb8453a498222C4fF2",
            "operator":"Equals"
        },
        {
            "name":"event",
            "value":"Transfer",
            "operator":"Equals (ignore case)"
        },
        {
            "name":"args",
            "operator":"Inspect",
            "operatorParameters":[
                {
                    "name":"dst",
                    "value":"0x52243C97DD8556fe1092084c199aeFAD4c34fD89",
                    "operator":"Equals (ignore case)"
                }
            ]
        }
    ],
    "targetType":"Event"
}

Kovan ETH Traces

{
    "alerts":[
        {
            "type":"Webhook (POST)",
            "payload":[
                {
                    "fieldName":"transactionHash",
                    "fieldType":"Field"
                },
                {
                    "fieldName":"trace",
                    "fieldType":"Sub Field",
                    "subPayloads":[
                        {
                            "fieldName":"action",
                            "fieldType":"Sub Field",
                            "subPayloads":[
                                {
                                    "fieldName":"to",
                                    "fieldType":"Field"
                                }
                            ]
                        }
                    ]
                }
            ],
            "parameters":{
                "url":"https://mywebhook.example/{transactionHash}/{args#src}"
            }
        }
    ],
    "targetMap":[
        {
            "name":"trace",
            "operator":"Inspect",
            "operatorParameters":[
                {
                    "name":"action",
                    "operator":"Inspect",
                    "operatorParameters":[
                        {
                            "name":"to",
                            "value":"0x52243C97DD8556fe1092084c199aeFAD4c34fD89",
                            "operator":"Equals (ignore case)"
                        }
                    ]
                }
            ]
        }
    ],
    "targetType":"Trace"
}

Full Alerting

Usage of all possible alert-triggers were all events (decoded logs) are matched that have:

  • address = 0xe3818504c1B32bF1557b16C238B2E01Fd3149C17
  • event = Transfer
  • to = 0x8d12A197cB00D4747a1fe03395095ce2A5CC6819
  • value > 999999
{
    "targetType":"Event",
    "targetMap":[
        {
            "name":"address",
            "value":"0xe3818504c1B32bF1557b16C238B2E01Fd3149C17",
            "operator":"Equals"
        },
        {
            "name":"event",
            "value":"Transfer",
            "operator":"Equals (ignore case)"
        },
        {
            "name":"args",
            "operator":"Inspect",
            "operatorParameters":[
                {
                    "name":"to",
                    "value":"0x8d12A197cB00D4747a1fe03395095ce2A5CC6819",
                    "operator":"Equals (ignore case)"
                },
                {
                    "name":"value",
                    "value":"999999",
                    "operator":"Greater",
                    "useScaledValue":true
                }
            ]
        }
    ],
    "alerts":[
        {
            "type":"Slack",
            "payload":[
                {
                    "fieldName":"transactionHash",
                    "fieldType":"Field"
                },
                {
                    "fieldName":"args",
                    "fieldType":"Sub Field",
                    "subPayloads":[
                        {
                            "fieldType":"Field",
                            "fieldName":"to"
                        }
                    ]
                }
            ],
            "parameters":{
                "url":"https://hooks.slack.com/services/myslackhookurl",
                "text":":warning: There has been a new alert match",
                "channel":"#alerting",
                "username":"#blockchain-alerting-bot"
            }
        },
        {
            "type":"Email",
            "payload":[
                {
                    "fieldName":"transactionHash",
                    "fieldType":"Field"
                },
                {
                    "fieldName":"args",
                    "fieldType":"Sub Field",
                    "subPayloads":[
                        {
                            "fieldType":"Field",
                            "fieldName":"to"
                        }
                    ]
                }
            ],
            "parameters":{
                "recipients":[
                    "user1@foobar.example",
                    "user2@foobar.example"
                ]
            }
        },
        {
            "type":"Webhook (GET)",
            "parameters":{
                "url":"https://mywebhook1.example/{transactionHash}/{args#to}"
            },
            "payload":[
                {
                    "fieldType":"Field",
                    "fieldName":"transactionHash"
                },
                {
                    "fieldType":"Sub Field",
                    "fieldName":"args",
                    "subPayloads":[
                        {
                            "fieldType":"Field",
                            "fieldName":"to"
                        }
                    ]
                }
            ]
        },
        {
            "type":"Webhook (POST)",
            "parameters":{
                "url":"https://mywebhook2.example"
            },
            "payload":[
                {
                    "fieldType":"Field",
                    "fieldName":"transactionHash"
                },
                {
                    "fieldType":"Sub Field",
                    "fieldName":"args",
                    "subPayloads":[
                        {
                            "fieldType":"Field",
                            "fieldName":"to"
                        }
                    ]
                }
            ]
        }
    ]
}

Interested or questions?

 

Sascha Göbel
(Co-Founder & Chief Technology Officer)
sascha@anyblockanalytics.com
+49 6131 3272372

    

Pin It on Pinterest