Skip to main content

Connect your Blockchain

Web3Auth is the frontend authentication system for your dApp. Once the user is authenticated, the Web3Auth SDK returns a provider. Using this provider we can sign transactions and make RPC calls to any blockchain.

import { Web3Auth } from "@web3auth/modal";
import Web3 from "web3";

const web3auth = new Web3Auth({
clientId, // get from
web3AuthNetwork: "sapphire_mainnet",
chainConfig: {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: "0x1", // EVM chain's Chain ID
rpcTarget: "", // EVM chain's RPC endpoint
// Avoid using public rpcTarget in production.
// Use services like Infura, Quicknode, Alchemy, Ankr etc.
displayName: "Ethereum Mainnet", // EVM chain's Name
blockExplorer: "", // EVM chain's Blockexplorer
ticker: "ETH", // EVM chain's Ticker
tickerName: "Ethereum", // EVM chain's Ticker Name

await web3auth.initModal();

const web3authProvider = await web3auth.connect();

const web3 = new Web3(web3authProvider);
const userAccounts = await web3.eth.getAccounts();

Using Web3Auth Providers

A provider is how libraries like web3.js & ethers.js talk to the blockchain. Providers take JSON-RPC requests and return the response. This is normally done by submitting the request to an HTTP or IPC socket-based server. Each adapter in Web3Auth exposes a Provider on successful user authentication. This provider can be used to interact with wallet or connected chain using RPC calls. Currently, Web3Auth supports providers for both EVM and Solana chains, which means that any EVM compatible chain & Solana can directly use our native providers to interact with the dApp. You can follow our API Reference to know more about how to use these providers with their compatible adapters:


Web3Auth providers give you a standard way of interacting with the blockchain. However, alongside that, it is recommended to use JSON RPC APIs, which help you connect to the blockchain without the need to run your own instance/ nodes. There are many services which offer a web API for accessing different blockchains:


Infura is the leading platform for Ethereum infrastructure. It provides a gateway to the Ethereum network, allowing developers to build and scale decentralized applications without having to run their own infrastructure. Most of the Web3Auth backend infrastructure runs on Infura APIs.


Quicknode is a managed blockchain node service that provides high-performance access to 15+ blockchains, including Ethereum, Gnosis (xDAI), Polygon, Binance Smart Chain, Avalanche, Fantom, Solana, Optimism, Arbitrum (+Nova), Algorand, Harmony, Celo, Terra and Bitcoin networks. They're the biggest node providers for the Solana Ecosystem, and our major partners for Solana infrastructure.


As a developer platform, Alchemy provides a suite of developer toolings and abstractions including JSON RPC APIs across all major chains, an ethers.js SDK, and a library of enhanced APIs like their NFT APIs.


Ankr is a decentralized cloud computing platform that provides a full suite of infrastructure services for blockchain developers. Most of the examples in our documentation use Ankr's Public JSON RPC APIs, to help you kickstart.

Web3Auth has multichain support

So, we have covered our existing wallet adapters and providers available. What if you want to use a different chain or a wallet?

Here the ability to expose the user's private key comes in handy. Every SDK of Web3Auth has the functionality of exposing the user's private key, within the dApp instance locally. This private key can be utilised by the dApp to interact with the chain.

The small API surface also means Web3Auth is composable - you can combine it with meta-transaction flows, multisigs, and other cryptographic protocols. It is easy to build on top of, and generally fits in with most other technology stacks, including but not limited to; your favorite scalability solutions, meta transactions, smart contract wallets, different elliptic curve pairs and even RSA.

Example below demonstrates usage of other chainNamespace and retrieving private key of logged in user.

const web3auth = new Web3Auth({
chainConfig: { chainNamespace: CHAIN_NAMESPACES.OTHER },
web3AuthNetwork: "sapphire_mainnet",
clientId: "example-client-id",

//Assuming user is already logged in.
async getPrivateKey() {
const privateKey = await web3auth.provider.request({
method: "private_key"
//Do something with privateKey

You can read more about this in our Provider SDK Reference


Currently only OpenloginAdapter is supported with other chainNamespace.