Defender Works Fine, But Not Getting Metamask Popup To Sign The Request

I have created a Defender and also added the autotasks for interacting with the relayer, and this is functioning properly. In my sample project, when clicking a button, it utilizes the webhook from the autotasks and then executes the transaction.

The issue I am facing is that the "from" address of the transaction belongs to the relayer, which is not the desired behavior. Instead, I want to use the wallet address of the user. Currently, I am not getting a popup from MetaMask to sign the request for the transaction.

:computer: Environment

:memo:Details

autotasks code

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

exports.handler = async function(event) {
  const provider = new DefenderRelayProvider(event);
  const signer = new DefenderRelaySigner(event, provider, { speed: 'fast' });
  // Use provider and signer for querying or sending txs from ethers, for example...
  const ADDRESS = '0x24D8aF7944869314B7EE6C34a5FF1582Ca6D4630'
  const gasLimit = 300000;
  const value  = event.request.body;
  const ABI =[...]

  const contract = new ethers.Contract(ADDRESS, ABI, signer);
	//await contract.register("Hello")
   await contract.register(value, { gasLimit });
}

how I am calling the webhook code

  const handleTriggerAutotask = async () => {
    try {
      const response = await fetch(
        "WEBHOOK_URL",
        {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify(inputData),
        }
      );

      const data = await response.json();
      setStatus(data.status);
    } catch (error) {
      console.error("Error triggering Autotask:", error);
      setStatus("Error");
    }
  };

:1234: Code to reproduce

I am directly calling the handleTriggerAutotask on a button click, but don't know how to integrate this with the metamask for signing the request

Hi @mishal

A relayer is a self contained wallet which does not utilise metamask. When you send your request to the autotask the relayer tx is signed inside the autotask and submitted to the network.

If you describe your use case and what you are trying to achieve I can point you in the right direction for implementing it

@dylkil
I am trying to implement the Gasless MetaTransactions.
https://www.youtube.com/watch?v=Bhz5LJbq9YY

like in this Video. Where a metamask pop up appears and requesting the user to sign it and this causes the transaction to initiate, by doing this the from address in the transaction is of the metamask and not the relayer.

The problem is that i am not sure how that part is done...

Hi @mishal

You can find the relevant code for doing this in the sendMetaTx func in this file https://github.com/OpenZeppelin/workshops/blob/master/01-defender-meta-txs/app/src/eth/register.js

This is a file inside the demo repo stephen used for the video, you can find all relevant code there

Thank you @dylkil I will surely try this out.