Defender Release 2020W50: Webhook Support, Fixed Gas Price & Valid Until

This release adds the highly requested webhook support for Autotasks, as well as new options for setting a fixed gas price and a valid until time that can be used in Relayer clients and Autotasks.

Webhook Support

With this release you now create Autotasks that are invoked via webhook. To do this, simply choose webhook as the trigger when creating the Autotask.

Trigger Webhook

Defender will create a secret URL for your Autotask, and invoke it whenever an HTTPS request is POSTed to that endpoint. You can regenerate this URL at any time.

Webhook Endpoint

When your Autotask is invoked via a webhook, you can access the HTTPS request info as part of the event parameter injected in your handler. Likewise, your return value will be included in the result field of the HTTP response payload.

exports.handler = async function(event) {
  const {
    body,    // Object with JSON-parsed POST body
    headers, // Object with key-values from HTTP headers
    queryParameters, // Object with key-values from query parameters
  } = event.request;
  return {
    hello: 'world' // JSON-serialized into response `result` field
  };
}

At the moment only JSON payloads are supported, and only non-standard headers with the X- prefix are provided to the Autotask. If any of these limitations is an issue for your use case, please reach out to us at defender@openzeppelin.com.

Fixed Gas Price

With this release we have added the ability to send a transaction with a fixed gas price by setting the gasPrice parameter. You can use this with your Defender private Relayer or inside your Autotasks as an alternative to the speed parameter (for which Defender Relay will adjust and bump the gas price according to your desired speed). If you use the gasPrice parameter, Defender Relay will never change the fixed gas price and the transaction will be mined with the exact gas price.

const { DefenderRelaySigner, DefenderRelayProvider } = require('defender-relay-client/lib/ethers');
const { ethers } = require('ethers');

const credentials = { apiKey: YOUR_API_KEY, apiSecret: YOUR_API_SECRET };
const provider = new DefenderRelayProvider(credentials);
// Will send transactions with a gas price set to 100 Gwei.
const signer = new DefenderRelaySigner(credentials, provider, { gasPrice: 100000000000 /* 100 Gwei */ });

const erc20 = new ethers.Contract(ERC20_ADDRESS, ERC20_ABI, signer);
const tx = await erc20.transfer(beneficiary, 1e18.toString());
const mined = await tx.wait();

Valid Until

Another new parameter introduced in this release for Defender Relay clients and Autotasks is the validUntil time. When this option is used, the transaction will be valid for submission to the Ethereum network until the given time. Note that you can combine validUntil with a fixed gas price to achieve extremely fast mining times and beating other transactions on gasPrice.

const { DefenderRelaySigner, DefenderRelayProvider } = require('defender-relay-client/lib/ethers');
const { ethers } = require('ethers');

const credentials = { apiKey: YOUR_API_KEY, apiSecret: YOUR_API_SECRET };
const provider = new DefenderRelayProvider(credentials);
// Will make transactions valid for two minutes.
const signer = new DefenderRelaySigner(credentials, provider, { validForSeconds: 120 });

const erc20 = new ethers.Contract(ERC20_ADDRESS, ERC20_ABI, signer);
const tx = await erc20.transfer(beneficiary, 1e18.toString());
const mined = await tx.wait();

Coming up

We are working on a new contract query tool in the Defender UI, adding the ability to Pause your contracts with one click from Admin, and a web3js version of the Defender Relay client!

2 Likes