Web3Auth / web3auth-web

Simple infrastructure that enables Web3 wallets and applications to provide seamless user logins for both mainstream and Web3.0 users.
https://web3auth.io/docs
Other
419 stars 227 forks source link

Cannot connect to EVM-compatible custom network rpc #859

Open peihsendoyle opened 1 year ago

peihsendoyle commented 1 year ago

We are trying to connect our custom network which is EVM-compatible and also metamask compatible as following: https://docs.kardiachain.io/docs/for-users/wallet/metamask-compatible

RPC_URL: https://rpc.kardiachain.io CHAIN_ID: 0x18 (integer 24) EXPLORER_URL: https://explorer.kardiachain.io SYMBOL: KAI

You can use Metamask to add our network and try to use as normal as Ethereum or BSC which is EVM-compatible as well.

We failed to connect by Web3Auth with following code:

async login() {
      this.web3auth = new Web3Auth({
        clientId: "CLIENT_ID",
        storageKey: "session",
        enableLogging: false,
        uiConfig: {
          loginMethodsOrder: ["facebook", "google"],
        },
        chainConfig: {
          chainNamespace: "eip155",
          chainId: "0x18",
          rpcTarget: "https://rpc.kardiachain.io",
          displayName: "KardiaChain",
          blockExplorer: "https://explorer.kardiachain.io",
          ticker: "KAI",
          tickerName: "KAI",
        },
      });
      const provider = await this.web3auth.connect();
      console.log("provider:", provider);
      const web3 = new Web3(provider);
      const address = (await web3.eth.getAccounts())[0];
      const balance = await web3.eth.getBalance(address);

Error on the console: Invalid network, net_version is 0

girishvi commented 1 year ago

@yashovardhan Could you please check this ?

Comments from [peihsendoyle]: we notice that our chain id on ChainList is 0 that's why chainId 0x0 works but cannot send transaction when configure chainId to 0x0

Saviour1001 commented 1 year ago

Hey there, you can just change the chain configurations of this react example and it works. I am able to create the private key and other functions like getBalance, signMessage etc work.

const web3auth = new Web3Auth({
          clientId,
          chainConfig: {
            chainNamespace: CHAIN_NAMESPACES.EIP155,
            chainId: "0x0",
            rpcTarget: "https://rpc.kardiachain.io", // This is the public RPC 
          },
          uiConfig: {
            theme: "dark",
            loginMethodsOrder: ["facebook", "google"],
            defaultLanguage: "en",
            appLogo: "https://web3auth.io/images/w3a-L-Favicon-1.svg", // Your App Logo Here
          },
        });

For sending transactions we are using the libraries ethers/web3, refer to the functions in the example above. Not able to test sendTransaction on my side as I don't have funds on the blockchain, but we are using Web3Auth to get the provider and then we are using external libraries to send transactions so should be working.