This Web3.js plugin adds support for the following wallet-related RPC methods:
- wallet_addEthereumChain (EIP-3085)
- wallet_switchEthereumChain (EIP-3326)
- wallet_watchAsset (EIP-747)
- wallet_requestPermissions (EIP-2255)
- wallet_getPermissions (EIP-2255)
- wallet_revokePermissions
Keep reading for more information, or refer to the comprehensive API documentation.
Use your preferred package manager. Ensure that web3
is also installed and integrated into your project.
npm install web3-plugin-wallet-rpc
yarn add web3-plugin-wallet-rpc
pnpm add web3-plugin-wallet-rpc
import { Web3 } from 'web3';
import { WalletRpcPlugin } from 'web3-plugin-wallet-rpc';
const web3 = new Web3('https://eth.llamarpc.com');
web3.registerPlugin(new WalletRpcPlugin());
Click on the method name for detailed documentation.
Invokes the wallet_addEthereumChain
method as defined in EIP-3085.
await web3.walletRpc.addEthereumChain({
chainId: 5000,
blockExplorerUrls: ['https://mantlescan.xyz'],
chainName: 'Mantle',
iconUrls: ['https://icons.llamao.fi/icons/chains/rsz_mantle.jpg'],
nativeCurrency: {
name: 'Mantle',
symbol: 'MNT',
decimals: 18,
},
rpcUrls: ['https://rpc.mantle.xyz'],
});
Invokes the wallet_switchEthereumChain
method as defined in EIP-3326.
await web3.walletRpc.switchEthereumChain(5000);
Invokes the wallet_watchAsset
method as defined in EIP-747.
await web3.walletRpc.watchAsset({
type: 'ERC20',
options: {
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
symbol: 'USDC',
},
});
Invokes the wallet_requestPermissions
method as defined in EIP-2255.
const permissions = await web3.walletRpc.requestPermissions({
eth_accounts: {},
});
Invokes the wallet_getPermissions
method as defined in EIP-2255.
const permissions = await web3.walletRpc.getPermissions();
Invokes the wallet_revokePermissions
method as defined in MetaMask docs.
const permissions = await web3.walletRpc.revokePermissions({
eth_accounts: {},
});
We welcome pull requests! For major changes, please open an issue first to discuss the proposed modifications. Also, ensure that you update tests as needed to reflect the changes.