Local Defender Action won't authenticate with proper keys

I'm trying to run an webhook action locally so I can iterate and test with a reasonable workflow.

Following the example from https://github.com/OpenZeppelin/defender-autotask-examples/tree/master/relay is close to working but I'm getting the following error:

Error: Failed to get a token for the API key XXXXXXX: Internal Server Error

The keys are correct and I can see that they're being assigned properly with a console.log of the Defender object:

Defender {
  apiKey: undefined,
  apiSecret: undefined,
  relayerApiKey: XXXXXXXXX,
  relayerApiSecret: XXXXXXXXXXXXXXXX,
  actionCredentials: undefined,
  actionRelayerArn: undefined,
  httpsAgent: undefined,
  retryConfig: undefined
}

Here's the code:

const ethers = require("ethers");

exports.main = async function (relayer) {
  console.log(relayer);
  const abi = ["function mint(address to, uint256)"];
  const iface = new ethers.utils.Interface(abi);

  const encodedData = iface.encodeFunctionData("mint", [
    "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    1999,
  ]);
  const txResult = await relayer.relaySigner.sendTransaction({
    to: "0xF21A33a27505bC2E3c96c516d6884e52c09c766e",
    speed: "fast",
    data: encodedData,
    gasLimit: "210000",
  });
  console.log(txResult);
};

// Entrypoint for the action
exports.handler = async function (client) {
  const relayer = new Defender(client);
  return exports.main(relayer);
};

// To run locally (this code will not be executed in actions)
if (require.main === module) {
  require("dotenv").config();
  const {
    RELAYER_API_KEY: relayerApiKey,
    RELAYER_API_SECRET: relayerApiSecret,
  } = process.env;
  exports
    .handler({ relayerApiKey, relayerApiSecret })
    .then(() => process.exit(0))
    .catch((error) => {
      console.error(error);
      process.exit(1);
    });
}

So far I'm unable to figure out the issue. Any help would be appreciated.

Hi we have more up to date examples of working with the Defender API here. We don't recommend using the https://github.com/OpenZeppelin/defender-autotask-examples/tree/master/relay repo as we will be deprecating the defender-relay-client package sometime in the future. Please ensure that you use defender-sdk package version 1.14.3 as version 1.14.2 has a bug.

1 Like

Thanks, it was the 1.14.2 bug biting me.

1 Like