Cannot read properties of undefined (reading 'body')

I'm trying to set up a sentinel that has a check with autotask condition checks.

:computer: Environment

Defender - Sentinel and Autotasks


I'm following @spalladino answer on another post as a guide.

I think I've followed everything, but I'm getting the following error when running the autotask:

Cannot read properties of undefined (reading 'body')

{"errorType":"TypeError","errorMessage":"Cannot read properties of undefined (reading 'body')","stack":["TypeError: Cannot read properties of undefined (reading 'body')","    at exports.handler (/var/task/index.js:2:44)","    at Runtime.handler (/opt/nodejs/autotask-wrapper.js:83:26)","    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1086:29)"]}

:1234: Code to reproduce

I basically want to check if the tokens of the specific wallet are under 1000. The sentinel is currently set up as having a condition where the "from" is the wallet address where the tokens are stored: (address is there)


exports.handler = async function (payload) {
  const conditionRequest = payload.request.body;
  const matches = [];
  const events =;
  const ethers = require('ethers');
  const IERC20 = require('@openzeppelin/contracts/build/contracts/IERC20.json');

  for (const evt of events) {
    const token = new ethers.Contract("contractAddress", IERC20.abi, ethers.getDefaultProvider());
    const balanceDistrPool = await token.balanceOf("walletAddress");
    let result = false;
    if(balanceDistrPool < 1000 * 10**18){
      result = true;
    // metadata can be any JSON-marshalable object (or undefined)
      hash: evt.hash,
      metadata: {
        lowBalance: result
  return { matches };

Am I doing this right?
Thanks :slight_smile: