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

Many errors occurred from the time I upgrade to 3.0.1 #137

Closed ductridev closed 2 years ago

ductridev commented 2 years ago

Describe the bug I'm using biconomy and many errors occurred when I upgraded from 2.0.34 to 3.0.1.

To Reproduce My code:

import { Biconomy } from "@biconomy/mexa";
import { ethers } from "ethers";

const biconomy = new Biconomy((window.ethereum), {
  walletProvider: window.ethereum,
  apiKey: process.env.REACT_APP_ETH_BICONOMY_APIKEY,
  debug: true
});

await biconomy.init();

biconomy.onEvent(biconomy.READY, () => {
        setLoading(false);
}).onEvent(biconomy.ERROR, (error: any, message: any) => {
  return (
    <div>
      <script>
        Something error! Refresh after <Countdown
          date={Date.now() + 5000}
          onComplete={() => { window.location.reload(); }}
        />
      </script>
    </div>
  );
});
if(!loading){
      let userSigner = new ethers.Wallet(window.privateKey);

      let rawTx = {
        from: buyerAddress,
        to: "0xACB39a14A04CEc3C33e53DCa92Ee8bd1e832ca46",
        value: ethers.utils.parseEther(Number(amountTo).toFixed(18)).toHexString(),
        nonce: await EthereumWeb3.getTransactionCount(buyerAddress, "latest"),
      };

      let signedTx = await userSigner.signTransaction(rawTx);

      console.log(signedTx);

      const forwardData = await biconomy.getForwardRequestAndMessageToSign(signedTx, buyerAddress);
      console.log(forwardData);

      const signature = await userSigner.signMessage(forwardData.personalSignatureFormat);

      let data = {
        signature: signature,
        forwardRequest: forwardData.request,
        rawTransaction: signedTx
      };

      let provider = biconomy.ethersProvider;

      let txHash = await provider.send("eth_sendRawTransaction", [data]);

      let receipt = await provider.waitForTransaction(txHash);
}

Expected behavior It should be run well because this is from tutorial at docs.

Screenshots image

Mexa SDK version (please complete the following information):

arcticfloyd1984 commented 2 years ago

Hey @ductridev There are a lot of breaking changes in SDK 3.0.0 and up. Would recommend to have a look at the docs for these changes: EIP 2771: https://docs.biconomy.io/products/enable-gasless-transactions/choose-an-approach-to-enable-gasless/eip-2771/2.-code-changes/sdk Custom Approach: https://docs.biconomy.io/products/enable-gasless-transactions/choose-an-approach-to-enable-gasless/custom-implementation/2.-code-changes/sdk

For code examples: https://docs.biconomy.io/products/enable-gasless-transactions/sdk-3

ductridev commented 2 years ago

Hi, according to this post: https://docs.biconomy.io/products/enable-gasless-transactions/choose-an-approach-to-enable-gasless/eip-2771/2.-code-changes/sdk#example-code You still using getForwardRequestAndMessageToSign which causes error at here!

ductridev commented 2 years ago

@arcticfloyd1984 please change docs at the link I have mentioned. As it's using getForwardRequestAndMessageToSign.