Failed to sign relayed transaction for 0xwalletAddress: Invalid request

Hi there,

I’m receiving this error when running gsn(v2.2.2) on hardhat (v2.3.3).

My smart contract that inherits BaseRelayRecipient
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.6;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

import "@opengsn/contracts/src/BaseRelayRecipient.sol";

/**
 * @title relayed smart contract
 * @dev a relayed smart contract
 */
contract RelayedSmartContract is Ownable, BaseRelayRecipient {
    // ---------------------------------------------------- Safe Math -----------------------------------------------------
    using SafeMath for uint256;

    // ------------------------------------------------------ Relay ------------------------------------------------------

    function _msgSender() internal override(Context, BaseRelayRecipient)
        view returns (address payable) {
            return BaseRelayRecipient._msgSender();
    }

    function _msgData() internal override(Context, BaseRelayRecipient)
        view returns (bytes memory ret) {
            return BaseRelayRecipient._msgData();
    }

    function setTrustedForwarder(address _trustedForwarder) public onlyOwner {
        trustedForwarder = _trustedForwarder;
    }

    /** 
     * Override this function.
     * This version is to keep track of BaseRelayRecipient you are using
     * in your contract. 
     */
    function versionRecipient() external pure override returns (string memory) {
        return "2.2.2";
    }

    // ------------------------------------------ smart contract business logic ------------------------------------------

    // VARS AND EVENTS HERE...

    /**
     * @dev Initializes the contract trusted forwarder
     */
    constructor(address _trustedForwarder) {
        trustedForwarder = _trustedForwarder;
    }   

    /**
     * @dev function to be relayed
     */
    function relayedFunction(uint someValue) public {
        // ... body
    }

    /**

     * @dev function to be relayed (onlyOwner)
     */
    function ownerFunction(uint someValue) public onlyOwner {
        // ... body
    }
}

Deployment script
const forwarder = require( '../build/gsn/Forwarder').address
const paymaster = require('../build/gsn/Paymaster').address

...

const TRUSTED_FORWARDER = forwarder

const RelayedSmartContract = await hre.ethers.getContractFactory("RelayedSmartContract");
const relayedSmartContract = await RelayedSmartContract.deploy(TRUSTED_FORWARDER);

await relayedSmartContract.deployed();

...

const config = { 
    paymasterAddress: paymaster,
      loggerConfiguration: {
          logLevel: 'debug',
          // loggerUrl: 'logger.opengsn.org',
      }
  }

const relayProvider = await RelayProvider.newProvider(
    { provider: await new Web3.providers.HttpProvider('http://127.0.0.1:8545'), config }
).init()

const web3Relay = new Web3(relayProvider);

const RelayedSmartContractRelay = await new web3Relay.eth.Contract(abiRelayedSmartContract, relayedSmartContract.address);

await RelayedSmartContractRelay.methods.relayedFunction(0).send({ from: "0xwalletAddress" });
Error log
interactor init start
calling sendAsync{"jsonrpc":"2.0","id":14,"method":"eth_sendTransaction","params":[{"from":"0xwalletAddress","data":"0x379607f50000000000000000000000000000000000000000000000000000000000000000","gasPrice":"0x1dcd65000","to":"0x1291be112d480055dafd8a610b7d1e203891c274"}]}
fetchRelaysAdded: found 2 events
fetchRelaysAdded: found unique relays: ["0x329eBf5FE07C455F55E5727c53A7F59f1E1E3468"]
== getRelayInfoForManagers: found 1 unique RelayServerRegistered events
nextRelay: find fastest relay from: [{"0":"0x329eBf5FE07C455F55E5727c53A7F59f1E1E3468","1":"0","2":"0","3":"http://127.0.0.1:43363","relayManager":"0x329eBf5FE07C455F55E5727c53A7F59f1E1E3468","baseRelayFee":"0","pctRelayFee":"0","relayUrl":"http://127.0.0.1:43363"}]
getRelayAddressPing URL: http://127.0.0.1:43363
pingResponse: {"relayWorkerAddress":"0x0ba7ac841a4f5b025dc4f700854da63d93f52932","relayManagerAddress":"0x329ebf5fe07c455f55e5727c53a7f59f1e1e3468","relayHubAddress":"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9","ownerAddress":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","minGasPrice":"8000000000","maxAcceptanceBudget":"285252","chainId":"31337","networkId":"31337","ready":true,"version":"2.2.2"}
race finished with a result: {"winner":{"pingResponse":{"relayWorkerAddress":"0x0ba7ac841a4f5b025dc4f700854da63d93f52932","relayManagerAddress":"0x329ebf5fe07c455f55e5727c53a7f59f1e1e3468","relayHubAddress":"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9","ownerAddress":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","minGasPrice":"8000000000","maxAcceptanceBudget":"285252","chainId":"31337","networkId":"31337","ready":true,"version":"2.2.2"},"relayInfo":{"0":"0x329eBf5FE07C455F55E5727c53A7F59f1E1E3468","1":"0","2":"0","3":"http://127.0.0.1:43363","relayManager":"0x329eBf5FE07C455F55E5727c53A7F59f1E1E3468","baseRelayFee":"0","pctRelayFee":"0","relayUrl":"http://127.0.0.1:43363"}},"errors":{"dataType":"Map","value":[]}}
attempting relay: {"pingResponse":{"relayWorkerAddress":"0x0ba7ac841a4f5b025dc4f700854da63d93f52932","relayManagerAddress":"0x329ebf5fe07c455f55e5727c53a7f59f1e1e3468","relayHubAddress":"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9","ownerAddress":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","minGasPrice":"8000000000","maxAcceptanceBudget":"285252","chainId":"31337","networkId":"31337","ready":true,"version":"2.2.2"},"relayInfo":{"0":"0x329eBf5FE07C455F55E5727c53A7F59f1E1E3468","1":"0","2":"0","3":"http://127.0.0.1:43363","relayManager":"0x329eBf5FE07C455F55E5727c53A7F59f1E1E3468","baseRelayFee":"0","pctRelayFee":"0","relayUrl":"http://127.0.0.1:43363"}} transaction: {"from":"0xwalletAddress","data":"0x379607f50000000000000000000000000000000000000000000000000000000000000000","gasPrice":"0x23c346000","gas":"0x117aa","to":"0x1291be112d480055dafd8a610b7d1e203891c274"}
Failed to relay call. Results:
Relaying errors (1):
http://127.0.0.1:43363 => Failed to sign relayed transaction for 0xwalletAddress: Invalid request
Error: Failed to relay call. Results:
Relaying errors (1):
http://127.0.0.1:43363 => Failed to sign relayed transaction for 0xwalletAddress: Invalid request
    at /project/node_modules/@opengsn/provider/src/RelayProvider.ts:141:20
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Alternatively, when running this through react, with the smart contract deployed on Kovan, using this address (0xdA78a11FD57aF7be2eDD804840eA7f4c2A38801d) as paymaster, I receive the following errors:

Error on kovan
pingResponse: {"relayWorkerAddress":"0xf928049a69dfdbd5579b573689bc125b64b2a1bb","relayManagerAddress":"0x02c475abf0db9c0b2ee30b702df07dd53ecde568","relayHubAddress":"0x727862794bdaa3b8Bc4E3705950D4e9397E3bAfd","ownerAddress":"0x8C1FD2DE219c98f5F88620422e36a8A32f83324E","minGasPrice":"6000000000","maxAcceptanceBudget":"285252","chainId":"42","networkId":"42","ready":true,"version":"2.2.2"}
RelaySelectionManager.ts:61 race finished with a result: {"winner":{"pingResponse":{"relayWorkerAddress":"0xf928049a69dfdbd5579b573689bc125b64b2a1bb","relayManagerAddress":"0x02c475abf0db9c0b2ee30b702df07dd53ecde568","relayHubAddress":"0x727862794bdaa3b8Bc4E3705950D4e9397E3bAfd","ownerAddress":"0x8C1FD2DE219c98f5F88620422e36a8A32f83324E","minGasPrice":"6000000000","maxAcceptanceBudget":"285252","chainId":"42","networkId":"42","ready":true,"version":"2.2.2"},"relayInfo":{"0":"0x02C475aBF0Db9C0b2EE30b702DF07Dd53ecde568","1":"0","2":"70","3":"https://kovan3-220.relays.opengsn.org/gsn1","relayManager":"0x02C475aBF0Db9C0b2EE30b702DF07Dd53ecde568","baseRelayFee":"0","pctRelayFee":"70","relayUrl":"https://kovan3-220.relays.opengsn.org/gsn1"}},"errors":{"dataType":"Map","value":[["0.0.0.0",{"message":"Request failed with status code 404","name":"Error","stack":"Error: Request failed with status code 404\n    at createError (http://localhost:3000/static/js/vendors~main.chunk.js:57921:15)\n    at settle (http://localhost:3000/static/js/vendors~main.chunk.js:58155:12)\n    at XMLHttpRequest.handleLoad (http://localhost:3000/static/js/vendors~main.chunk.js:57395:7)","config":{"url":"0.0.0.0/getaddr","method":"get","headers":{"Accept":"application/json, text/plain, */*"},"transformRequest":[null],"transformResponse":[null],"timeout":15000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1}}]]}}
RelayClient.ts:247 attempting relay: {"pingResponse":{"relayWorkerAddress":"0xf928049a69dfdbd5579b573689bc125b64b2a1bb","relayManagerAddress":"0x02c475abf0db9c0b2ee30b702df07dd53ecde568","relayHubAddress":"0x727862794bdaa3b8Bc4E3705950D4e9397E3bAfd","ownerAddress":"0x8C1FD2DE219c98f5F88620422e36a8A32f83324E","minGasPrice":"6000000000","maxAcceptanceBudget":"285252","chainId":"42","networkId":"42","ready":true,"version":"2.2.2"},"relayInfo":{"0":"0x02C475aBF0Db9C0b2EE30b702DF07Dd53ecde568","1":"0","2":"70","3":"https://kovan3-220.relays.opengsn.org/gsn1","relayManager":"0x02C475aBF0Db9C0b2EE30b702DF07Dd53ecde568","baseRelayFee":"0","pctRelayFee":"70","relayUrl":"https://kovan3-220.relays.opengsn.org/gsn1"}} transaction: {"from":"0xwalletAddress","data":"0x379607f50000000000000000000000000000000000000000000000000000000000000000","gasPrice":"0x1ad274800","gas":"0x119d7","to":"0xsmartContractAddress"}
RelayClient.ts:374 Created HTTP relay request: {"relayRequest":{"request":{"to":"0xsmartContractAddress","data":"0x379607f50000000000000000000000000000000000000000000000000000000000000000","from":"0xwalletAddress","value":"0","nonce":"0","gas":"72151","validUntil":"25561729"},"relayData":{"pctRelayFee":"70","baseRelayFee":"0","gasPrice":"7200000000","paymaster":"0xdA78a11FD57aF7be2eDD804840eA7f4c2A38801d","paymasterData":"0x","clientId":"1","forwarder":"0x7eEae829DF28F9Ce522274D5771A6Be91d00E5ED","relayWorker":"0xf928049a69dfdbd5579b573689bc125b64b2a1bb"}},"metadata":{"relayHubAddress":"0x727862794bdaa3b8Bc4E3705950D4e9397E3bAfd","signature":"0x8b8713f6813e2b85cf89533cf7041962f7a330417b4727f6955ba8e9d60add3903e228c1290b7667d9106a975bd0bc956f40b4bb54082818a6245f627e02858c1c","approvalData":"0x","relayMaxNonce":25}}
ContractInteractor.ts:357 relayCall res=0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006408c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c77726f6e6720746172676574000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
index.js:1 Failed to relay call. Results:
Ping errors (1):
0.0.0.0 => Request failed with status code 404
Relaying errors (1):
https://kovan3-220.relays.opengsn.org/gsn1 => paymaster rejected in local view call to 'relayCall()' : wrong target

The direct call to the function using my wallet work as expected (both on hardhat test net and Kovan), but the realy throw the errors above on both networks.

Let me know if I need to share any further details, thanks a lot.

Doesn’t look like a gsn error. Looks like you pass the string “0xwalletAddress”, probably instead of “0x”+walletAddress

Btw, I just replaced the address there with 0xwalletAddress to make it easy to understand. On hardhat testnet it’s 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266.

If I understand your reply correctly @drortirosh , on hardhat testnet for example, I should send "0x"+f39Fd6e51aad88F6F4ce6aB8827279cffFb92266 somewhere? Could you point me to the part I should do that?

You shouldn’t use GSN during deployment: GSN is all about calling contract methods without paying gas.
You can’t directly deploy through GSN
You should use RelayProvider only in your test app itself.
please see our sample workshop, for the changes (to app and to deployment) to use GSN.