Watch contracts
Monitor state changes for a specific smart contract
ContractsTrigger
type triggers allow you to track state changes for a specific smart contract variable (exposed via getter function) or any kind of value returned by a view Solitidy/Viper function.Let's see how we can use a
ContractTrigger
to monitor state changes on Uniswap. We can use the getTokenToEthOutputPrice
function to know how many MKR is 1 ETH worth. It is simple to create a trigger that sends us an email every time the ETH price drops below a certain threshold:{
"name":"ETH price drop",
"type":"ContractsTrigger",
"statement":{
"contract":{
"address":"0x09cabec1ead1c0ba254b09efb3ee13841712be14",
"abi":[
{
"abi":"..."
}
]
},
"method":{
"name":"getTokenToEthOutputPrice"
},
"inputs":[
{
"type":"uint256",
"name":"getTokenToEthOutputPrice",
}
],
"outputFilters":[
{
"condition":{
"predicate":"SmallerThan",
"attribute":"200"
},
"parameter":{
"name":"eth_bought",
"type":"uint256"
}
}
]
},
"actions":[
{
"type":"Email",
"attributes":{
"body":"On block number $BlockNumber$",
"subject":"ETH PRICE DROP! last value was: $ReturnedValues$",
"to":[
]
}
}
]
}
Here is a summary of the supported types and predicates:
Type | Supported predicates |
int8...256 , uint8...256 | Eq, SmallerThan, BiggerThan |
int8...256[N] , uint8...256[N], address[N], string[N], bytes1...32[N] | Eq, SmallerThan, BiggerThan, IsIn* |
address , string , bytes1...32 , bool | Eq |
It is also possible to define more complex data types as inputs to our trigger this way:
{
"inputs":[
{
"type":"tuple[]",
"name":"orders",
"components":[
{
"name":"makerAddress",
"type":"address",
"value":"0x..."
},
{
"name":"takerAddress",
"type":"address",
"value":"0x..."
},
{
"name":"feeRecipientAddress",
"type":"address",
"value":"0x..."
}
]
},
{
"type":"address",
"name":"token",
"value":"0x..."
},
{
"type":"address[4]",
"name":"tradeAddresses",
"value":[
"0x...",
"0x...",
"0x...",
"0x..."
]
}
]
}
Last modified 3yr ago