nahmii / nahmii-2-sdk

The `@nahmii/sdk` package is an SDK to interact with Nahmii 2.0.
https://www.nahmii.io/
1 stars 2 forks source link

Signer connect unsupported operation #15

Closed HDauven closed 2 years ago

HDauven commented 2 years ago

Describe the bug The current setup for connecting to a smart contract does not play well with MetaMask. The JSON-RPC signer exposed by MetaMask does not allow the connect function to be used. A given signer can thus not connect to a provider.

To Reproduce Steps to reproduce the behavior:

  1. Integrate the @nahmii/sdk.
  2. Call the relayL2ToL1Messages function with a signer retrieved from a JSON-RPC provider exposed by Ethers.
  3. The following error will be thrown:
    index.ts:225 Uncaught (in promise) Error: cannot alter JSON-RPC Signer connection (operation="connect", code=UNSUPPORTED_OPERATION, version=providers/5.5.1)
    at Logger.makeError (index.ts:225)
    at Logger.throwError (index.ts:237)
    at JsonRpcSigner.connect (json-rpc-provider.ts:145)
    at relayL2ToL1Messages (l2-to-L1-message-relaying.js:94)
    at async TransactionTable.claimFunds (Account.svelte:105)

Expected behavior The function can be called without throwing the above mentioned error.

Additional context The problem can be resolved by not relying on the connect function, but instead pass a JSON-RPC provider that is also a signer. This is a small refactor where every connect call will be removed and instead the called smart contracts are instantiated and the JSON-RPC signer is passed into the instantiation call.