Default EVM Adapter
@web3auth/default-evm-adapter
The default EVM adapter enables seamless detection of injected EVM wallets and WalletConnect-supported wallets, allowing interaction with just a single line of code.
Basic Details
Adapter Name: default-evm-adapter
Package Name: @web3auth/default-evm-adapter
authMode: DAPP
chainNamespace: EIP155
Default: NO
Installation
- npm
- Yarn
- pnpm
npm install --save @web3auth/default-evm-adapter
yarn add @web3auth/default-evm-adapter
pnpm add @web3auth/default-evm-adapter
Injected Wallets
To automatically fetch all the available EVM wallets in browser context, you should use the
getInjectedAdapters
function. This function uses MIPD (EIP6163) so all available wallets in the
browser will automatically be detected.
In case of PnP Modal SDK, if no wallets are available, prompts users with an option to install one. Refer to the image below for details:
Parameter
- Table
- Interface
Parameter | Description |
---|---|
options | Accepts IWeb3AuthCoreOptions used to initialize the Web3Auth SDK. |
export declare const getInjectedAdapters: (params: {
options: IWeb3AuthCoreOptions;
}) => Promise<IAdapter<unknown>[]>;
Usage
import { getInjectedAdapters } from "@web3auth/default-evm-adapter";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
const chainConfig = {
chainId: "0xaa36a7",
displayName: "Ethereum Sepolia",
chainNamespace: CHAIN_NAMESPACES.EIP155,
tickerName: "Ethereum Sepolia",
ticker: "ETH",
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
blockExplorerUrl: "https://sepolia.etherscan.io",
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
};
const privateKeyProvider = new EthereumPrivateKeyProvider({ config: { chainConfig } });
const web3AuthOptions: Web3AuthOptions = {
clientId,
chainConfig
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider: privateKeyProvider,
};
const adapters = await getInjectedAdapters({ options: web3AuthOptions });
adapters.forEach((adapter) => {
web3auth.configureAdapter(adapter);
});
WalletConnect-supported Wallets
To list all the wallets supported by the WalletConnect list, you can use the
getDefaultExternalAdapters
function.
In case of PnP Modal SDK, if no wallets are available, it provides an option to use the WalletConnect v2 to connect the wallet. Refer to the image below for details:
Parameter
- Table
- Interface
Parameter | Description |
---|---|
options | Accepts IWeb3AuthCoreOptions used to initialize the Web3Auth SDK. |
export declare const getDefaultExternalAdapters: (params: {
options: IWeb3AuthCoreOptions;
}) => Promise<IAdapter<unknown>[]>;
Usage
import { getDefaultExternalAdapters } from "@web3auth/default-evm-adapter";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
const chainConfig = {
chainId: "0xaa36a7",
displayName: "Ethereum Sepolia",
chainNamespace: CHAIN_NAMESPACES.EIP155,
tickerName: "Ethereum Sepolia",
ticker: "ETH",
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
blockExplorerUrl: "https://sepolia.etherscan.io",
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
};
const privateKeyProvider = new EthereumPrivateKeyProvider({ config: { chainConfig } });
const web3AuthOptions: Web3AuthOptions = {
clientId,
chainConfig
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider: privateKeyProvider,
};
const adapters = await getDefaultExternalAdapters({ options: web3AuthOptions });
adapters.forEach((adapter) => {
web3auth.configureAdapter(adapter);
});