I was playing around with OZ Defender (great product!), and I thought it would be nice to share another working example for the first timer. Below is an Autotask script that reads Maker’s ilkRegistry
contract and poke
s the spot
contract on Kovan.
const { ethers } = require("ethers");
const { DefenderRelaySigner } = require('defender-relay-client/lib/ethers');
// Entrypoint for the Autotask
exports.handler = async function(credentials) {
// Initialize default provider and defender relayer signer
const provider = ethers.getDefaultProvider('kovan');
const signer = new DefenderRelaySigner(credentials, provider, {
speed: 'fast',
from: '0xABC123',
});
let ilkRegistryAddy = '0xedE45A0522CA19e979e217064629778d6Cc2d9Ea'
let ilkRegistryABI = [
"function list() external view returns (bytes32[] memory)",
"function name(bytes32 ilk) external view returns (string memory)"
];
const ilkRegistry = new ethers.Contract(ilkRegistryAddy,
ilkRegistryABI,
signer);
let spotAddy = '0x3a042de6413eDB15F2784f2f97cC68C7E9750b2D';
let spotABI = ["function poke(bytes32 ilk) external"];
const spot = new ethers.Contract(spotAddy,
spotABI,
signer);
console.log(`Poking Spotter at ${spotAddy}`);
let list = await ilkRegistry.list();
for (const ilk of list) {
await spot.poke(ilk);
let name = await ilkRegistry.name(ilk);
console.log(`Poked ${name}`);
}
}