walletAddChain method
Creates a confirmation asking the user to add the specified chain with chainId
, chainName
, nativeCurrency
, and rpcUrls
to MetaMask.
The user may choose to switch to the chain once it has been added.
As with any method that causes a confirmation to appear, wallet_addEthereumChain
should only be called as a result of direct user action, such as the click of a button.
// Add chain 97
await ethereum!.walletAddChain(
chainId: 97,
chainName: 'Binance Testnet',
nativeCurrency: CurrencyParams(name: 'BNB', symbol: 'BNB', decimals: 18),
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545/'],
);
Implementation
Future<void> walletAddChain({
required int chainId,
required String chainName,
required CurrencyParams nativeCurrency,
required List<String> rpcUrls,
List<String>? blockExplorerUrls,
}) =>
request('wallet_addEthereumChain', [
_ChainParamsImpl(
chainId: '0x' + chainId.toRadixString(16),
chainName: chainName,
nativeCurrency: nativeCurrency.impl,
rpcUrls: rpcUrls,
blockExplorerUrls: blockExplorerUrls,
)
]);