Search documentation

Alerting Examples

Monitor ERC-20 Token Movements in and out of an 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

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