.env values not working

I wrote the script below locally and created a task with defender-autotask-client


const {
} = require("defender-relay-client/lib/ethers");

const { execute } = require("../task");

exports.handler = async function () {
  const contractAddress = process.env.CONTRACT_ADDRESS;
  const abi = [{.....}];

  const credentials = {
    apiKey: process.env.RELAY_API_KEY,
    apiSecret: process.env.RELAY_API_SECRET,

  const provider = new DefenderRelayProvider(credentials);
  const signer = new DefenderRelaySigner(credentials, provider, {
    speed: "fast",

  await execute(contractAddress, abi, signer);

Got this error when triggered

When I create a task with the direct value the .env helped with it, everything worked well.

When you created the Autotask, did you specify the ID of the Relayer you are wanting to use?

An Autotask can connect to a Relayer using injected credentials (read more about this here).

Yes I did, the values for RELAY_API_KEY and RELAY_API_SECRET handles that.

When you upload the Autotask code to Defender, the environment is no longer the local one, and so the variables saved in your .env file aren't available.

By specifying the Relayer ID during the creation of the Autotask, the Relayer credentials are supplied by Defender. All that's needed is to supply the event as the credentials. You can see an example here.