This setup shows how to pause contract on Spotter alert.
Setup Defender
- Create a Defender relay and send some native currency (ETH, BNB, etc) to this address, so it can cover transaction cost.
- Create a Defender autotask with webhook trigger and connect your relayer to it.
Here is an example of the autotask code to pause your contract.
const { Relayer } = require('defender-relay-client');
const { ethers } = require('ethers');
const your_contract = "0x72876a20Ca6b383b5401CD5FC97ed693d26dF43C"
exports.handler = async function(event) {
if('subscribe' in event.request.body
&& 'address' in event.request.body.subscribe
&& event.request.body.subscribe.address == your_contract) {
console.log(event.request.body.subscribe);
const relayer = new Relayer(event);
let ABI = [
"function pause()"
];
let iface = new ethers.utils.Interface(ABI);
const tx_pause = await relayer.sendTransaction({
to: your_contract,
value: 0,
gasLimit: '100000',
speed: 'fast',
data: iface.encodeFunctionData("pause", [])
});
console.log("tx pause sended", tx_pause.hash);
}
return "ok";
}
Using webhook to receive Spotter alert
Use /webhook
command in Spotter telegram bot and send URL webhook from defender.
Setup Spotter subscription
Use /add
command in Spotter to subscribe on alerts for the addresses of interest. For the example above it is 0x72876a20Ca6b383b5401CD5FC97ed693d26dF43C
on BSC.