ethers.provider.Web3Provider(gsnProvder) returns unknown accounts when using signer.signMessage()

I’m stumped.

The suggested RelayProvider setup has been working great so far:

let gsnProvider = await RelayProvider.newProvider({
      provider: new Web3HttpProvider(process.env.NEXT_PUBLIC_TEST_HTTP_CONNECTION),
      config: gsnConfig
let from = gsnProvider.newAccount().address
let ethersGSNProvider = new ethers.providers.Web3Provider(gsnProvider)
let signer = ethersGSNProvider.getSigner(from)
await <contract>.connect(signer).stateUpdate()

however I’m finding myself needing to sign a custom message:

await signer.signMessage(ethers.utils.arrayify(payloadHash))

however I’m getting an error:

unknown account 0cf3...

Wrapping the gsnProvider in new ethers.providers.Web3Provider(gsnProvider) doesn’t preserve the sendMessage function we get with default accounts (ethersGSNProvider.getSigner(0)).

Is there someway around this without resorting to using raw private keys?

gsnProvider.newAccount() is limited to GSN functionality.
You’d better add the account to the underlying web3 account,
sender = new Web3(web3Provider).personal.newAccount('password)

Thank you for bringing this up. We’ll try to fix it in future version.

1 Like