thirdweb-dev / js

Best in class web3 SDKs for Browser, Node and Mobile apps
https://thirdweb.com
Apache License 2.0
420 stars 314 forks source link

XRPL EVM Sidechain Issue wrong network config #2214

Closed GoulvenFrs closed 7 months ago

GoulvenFrs commented 7 months ago

Hi,

I'm creating an app on Expo React Native.
I'm building on the xrpl evm sidechain. I have an issue when interracting with the smarts contracts : the chainId is not up to date !

I checked in @thirdweb-dev/chain and I found out that you are using the xrong chainID : 1440001 instead of 1440002.

The new chain Id is 1440002 ... and from what I saw it's been going on since several months ...

I tried to use a custom network :

const customChain = {

chainId: 1440002, rpc: ["https://rpc-evm-sidechain.xrpl.org"],

nativeCurrency: { decimals: 18, name: "XRP", symbol: "XRP", }, shortName: "XRPL", slug: "XRPL", testnet: true, chain: "XRPL EVM Sidechain Devnet", name: "XRPL EVM Sidechain Devnet", };

But faced this error : "Error: unsupported getDefaultProvider network (operation="getDefaultProvider", network=" rpc-evm-sidechain.xrpl.org", code=NETWORK_ERROR, version=providers/5.7.2) at EmbeddedWallet._connect2 (base-66428998.browser.esm.js:332:1) at async EmbeddedWallet.connect (base-66428998.browser.esm.js:222:1)"

Is there any mays to fix this ?

Have a good day !

warengonzaga commented 7 months ago

Hello @GoulvenFrs thank you for creating this issue from our Discord support. Adding @Yash094 and @nkrishang here to take a look about the issue. cc: @jnsdls

MananTank commented 7 months ago

Hi @GoulvenFrs

Can you add details on how are you connecting the EmbeddedWallet? Are you using ConnectWallet component or useEmbeddedWallet hook?

GoulvenFrs commented 7 months ago

Hi @MananTank :)

I'm using useEmbeddedWallet hook !

Long story short, you need to change the chainID of XrpLedgerEvmDevnetSidechain from 1440001 to 1440002 following the official documentation : https://opensource.ripple.com/docs/evm-sidechain/connect-metamask-to-xrpl-evm-sidechain/

Let me walk you throught the problems and what I found so far :

1. The login set up :

import { XrpLedgerEvmDevnetSidechain,Sepolia } from "@thirdweb-dev/chains";

 <ThirdwebProvider
        activeChain={Sepolia }
        clientId={process.env.EXPO_PUBLIC_3RDWEB_CLIENT_ID}
        supportedWallets={[
          embeddedWallet({
            auth: {
              options: ["email", "google", "apple", "facebook"],
            },
          }),
        ]}
        autoConnect={true}
      >
        {children}
</ThirdwebProvider>
 const {connect} = useEmbeddedWallet();

 async function socialLogin(type){
      const url = Linking.createURL()
      try {
        const wallet = await connect({
          strategy: type,
          redirectUrl: url
        })
        if (wallet) {
          const walletAddress = await wallet.getAddress()
          const email =  wallet.getEmail();
          const res = await handleLogin(walletAddress,email)
          if(res===true){
            return true
          }else{
            return false
          }
        } else {
          console.log(wallet ,"Error signing in. Please try again later.");
          return false
        }
      } catch (error) {
        console.error(`Error socialLogin: `, error )
        return false
      }
  }

The connection works perfectly fine with both XrpLedgerEvmDevnetSidechain and Sepolia.

2. The smarts contract set up :

The functions to read and write the smart contract :


// read
const value1 = useContractRead( contractStorage1,"retrieve");

// write 
  const { mutateAsync: store,} = useContractWrite(contractStorage1, "store")

  async function call() {
    try {
      const data = await store({ args: [6] });
      console.info("contract call successs", data);
    } catch (err) {
      console.error("contract call failure", err);
    }
  }

I tried to interract with a simple Storage smart contract and here is what happened : (I deployed the smarts contracts using Remix )

And there a weird thing happened : I am able to read the datas of the contract on the dapp (the thirdWeb provider's active chain was your XrpLedgerEvmDevnetSidechain (1440001) ) but I whenever I try to write the contract this error appears : err_xrpl_write_1440001

On the error message I discovered that the chainID used doesn't coorespond to the xrpl evm sidechain documentation : config_xrpl_evm_sidechain (https://opensource.ripple.com/docs/evm-sidechain/connect-metamask-to-xrpl-evm-sidechain/)

I's weird that I'm able to read the datas from the smart contract even if the chainID doesn't correspond.

I thought that it could be because I didn't imported the contract into Thirdweb dashboard ... so I tried to import the smart contract on the network 1440001 (the one you're using even if it doesn't correspond to the official documentation) and obviously it didn't worked : err_import_1440001 ( btw the error mention that the smart contract isn't verified wich is false : https://evm-sidechain.xrpl.org/address/0x2603CFb7e08e31035c3C027b9C12aD66cBD3613A/)

Then, still on the thirdweb dashboard I tried to import the smart contract on the network 1440002 and this time I have a new error (nothing happen on the UI, I had to check the devtools ) : err_import_1440002

So that's an issue ...

3. Custom network set up :

Then I tried to set up a custom network coorespong to XRPL EVM SIDECHAIN officials docs :

const customChain = {
  // Required information for connecting to the network
  chainId: 1440002, // Chain ID of the network
  rpc: [" https://rpc-evm-sidechain.xrpl.org"], // Array of RPC URLs to use

  // Information for adding the network to your wallet (how it will appear for first time users) === \\
  // Information about the chain's native currency (i.e. the currency that is used to pay for gas)
  nativeCurrency: {
    decimals: 18,
    name: "XRP",
    symbol: "XRP",
  },
  shortName: "XRPL", // Display value shown in the wallet UI
  slug: "XRPL", // Display value shown in the wallet UI
  testnet: true, // Boolean indicating whether the chain is a testnet or mainnet
  chain: "XRPL EVM Sidechain Devnet", // Name of the network
  name: "XRPL EVM Sidechain Devnet", // Name of the network
};

I used this network for the ThirdWeb provider ( the same way as Sepolia and your XRPL version).

And ... the connection doesn't works : err_custm_network_1440002

So I guess if I had to summerize all of that : with your vesrion of xrpl we can't interract (write) with the smarts contracts ; with real verion of xrpl we can't connect ... I see one solution for both : fix the chainID and maybe the block explorer you use to see if a smart contract is veriified or not.

Normally with all this you can reproduce easily ( at least I hope :) ) , have a good day and if I can help it will be with pleasure !

PS : for good mesure here are the dependencies used in my package.json :

    "@thirdweb-dev/chains": "^0.1.62",
    "@thirdweb-dev/react": "^4.1.17",
    "@thirdweb-dev/react-native": "^0.5.2",
    "@thirdweb-dev/react-native-compat": "^0.5.2",
    "@thirdweb-dev/sdk": "^4.0.23",
GoulvenFrs commented 7 months ago

Hi, @MananTank, @warengonzaga, @assimovt, @sebas5384 :)

I took a day to investigate and at least an hour to give you a detailed report of what I observed in order to save you time... A week has gone by since my reply and I've had no news, even acknowledgement of receipt.

How can I help you unblock the situation ?

MananTank commented 7 months ago

Hi @GoulvenFrs, Sorry for the delay here and Thanks for the detailed explanation. I understand that the chain id is incorrect and we will fix this asap.

I'm also trying to get some testnet funds for the "XRP Ledger EVM Devnet Sidechain" to test this out but I'm not able to find how to do so. Can you point me in the right direction on how to get testnet funds?

GoulvenFrs commented 7 months ago

Hi @MananTank, it's ok, I didn't wanted to sound rude :)

For now here is my way to get faucets on the sidechain evm :

  1. I use Xaman to get faucet on the native XRP Ledger
  2. I use add the sidechain devnet to metamask : https://opensource.ripple.com/docs/evm-sidechain/connect-metamask-to-xrpl-evm-sidechain/
  3. I bridge the faucets from XRPL Devnet to XRPL SiDECHAIN EVM DEVNET : https://bridge.devnet.xrpl.org/

If you need help and why not build a collaboration to develop your services on this network, I am directly in contact with Peersyst the company responsible for this network (with Ripple) , I will be happy to help you => you can contact me on my email to make it happen.

GoulvenFrs commented 7 months ago

Quick follow up after discussing with Peersyst : you can get faucets directly on the bridge :)

MananTank commented 7 months ago

Hey @GoulvenFrs - Thanks for this, I was able to replicate the issue.

We have updated the chainId in our api-server and RPC and we will soon release the update to @thirdweb-dev/chains package - however even after fixing the chainId - the contract read and write are not working. I've relyed this issue to the team and they are looking into this issue

MananTank commented 7 months ago

Hey @GoulvenFrs - Thanks for your patience on this issue. There was an issue in the contract-api server which has been resolved - It now properly imports the ABI of the contract on XRPL EVM Sidechain

Also, please install the latest version of @thirdweb-dev/chains package to get the updated chainId in the chain object

npm i @thirdweb-dev/chains@latest

let me know if you face any issue after that