bcnmy / mexa-sdk

Repository contains mexa sdk code that can be plugged into your dapp and can leverage meta transaction feature.
MIT License
106 stars 41 forks source link

Incompatibility between Web3Auth and Biconomy w/ React TS (error while getting transaction receipt) #146

Closed mdr-altdev closed 2 years ago

mdr-altdev commented 2 years ago

Describe the bug

I want to use Biconomy + Web3Auth in a Next.js typescript project, and I found an issue with the provider interfaces. I am using web3 1.7.3, @web3auth/web3auth 2.0.2, @biconomy/mexa 3.0.4

This is the way I initialize Web3Auth + Biconomy (classic way):

const web3auth = new Web3Auth({
  clientId,
  chainConfig: {
    chainNamespace: "eip155",
    chainId: "0x13881",
    rpcTarget: "https://polygon-mumbai.infura.io/v3/{INFURA_PROJ_ID}",
  },
})
await web3auth.initModal()

if (web3auth.provider) {
  const biconomy = new Biconomy(web3auth.provider, {
    apiKey: apiKey,
    debug: true,
    contractAddresses: [HelloWriter],
  })
  await biconomy.init()
}

After init, I wish to call a contract function using biconomy.provider (which comes from the web3auth.provider). The call actually works, and the transaction is mined (in the Biconomy debug logs, I can see Tx Hash mined message received at client with id...), however the eth_getTransactionReceipt call fails:

invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash

I am suspecting an incompatibility between the web3auth provider (which is expected to be EIP1193) and the ExternalProvider interface used within Biconomy.

I know that @shahbaz17 made a working example of Web3Auth + Biconomy (https://github.com/shahbaz17/biconomy-web3auth-example), and I can also reproduce it on my side, but I can't figure out how to make it work in a Typescript React environment (tested both with Next and vanilla React), built with the NPM packages and not using the ones from the CDN.

It is worth noting than when I switch to ethers.js (while doing exactly the same thing), the transaction doesn't succeed: it is broadcast to the RPC node, but it fails.

To Reproduce

I am using Web3Auth's nextjs-evm-web3auth-example template as a basis, on top of which I have only added the Biconomy conf, as well as a very simple call to a ERC2771-enabled ERC721 contract. This is the repo: https://github.com/mdr-altdev/web3auth-biconomy-poc

This is deployed on Vercel: https://web3auth-biconomy-poc-eu5k.vercel.app/ -> After logging in (whether with Metamask or social login), click "Mint NFT" to reproduce

Expected behavior

I would expect the eth_getTransactionReceipt request made by the provider not to fail, and receive a proper notification when the tx goes through.

Screenshots

Here are the logs that I get (most of them are on the Biconomy side, with debug enabled):

Screen Shot 2022-10-02 at 13 02 28

Device Info (please complete the following information):

kunal047 commented 2 years ago

The response to eth_getTransactionReceipt would be null unless the transaction is mined. So, ideally, you can subscribe to the txMined event to receive a notification when the transaction goes through.