Skip to main content

wallet_addEthereumChain

MetaMask

Creates a confirmation asking the user to add the specified chain to the wallet application. The caller must specify a chain ID and some chain metadata. The wallet application may refuse or accept the request. null is returned if the chain is added, and an error otherwise. Introduced by EIP 3085.

Params

(1)

1. AddEthereumChainParameter (required)

chainId
string
required

MUST specify the integer ID of the chain as a hexadecimal string, per the eth_chainId Ethereum RPC method. The wallet SHOULD compare the specified chain ID value with the eth_chainId return value from the endpoint. If these values aren't identical, the wallet MUST reject the request.

blockExplorerUrls
array[string]

If provided, MUST specify one or more URLs pointing to block explorer sites for the chain.

chainName
string

If provided, MUST specify a human-readable name for the chain.

iconUrls
array[string]<uri>

If provided, MUST specify one or more URLs pointing to reasonably sized images that can be used to visually identify the chain.

nativeCurrency
NativeCurrency

If provided, MUST describe the native currency of the chain using the name, symbol, and decimals fields.

decimals
integer
required

A non-negative integer.

name
string
required

SHOULD be human-readable.

symbol
string
required

SHOULD be human-readable.

rpcUrls
array[string]

Result

(AddEthereumChainResult)
null

Errors

CodeMessage
-32602Expected null or array with at least one valid string HTTPS URL 'blockExplorerUrl'. Received: ${blockExplorerUrls}
-32602Expected 0x-prefixed, unpadded, non-zero hexadecimal string 'chainId'. Received: ${chainId}
-32602Invalid chain ID "${_chainId}": numerical value greater than max safe value. Received: ${chainId}
-32602May not specify default MetaMask chain.
-32602Expected 2-6 character string 'nativeCurrency.symbol'. Received: ${ticker}
-32602nativeCurrency.symbol does not match currency symbol for a network the user already has added with the same chainId. Received: ${ticker}

Example

Request

await window.ethereum.request({
"method": "wallet_addEthereumChain",
"params": [
{
"chainId": "0x64",
"chainName": "Gnosis",
"rpcUrls": [
"https://rpc.ankr.com/gnosis"
],
"iconUrls": [
"https://xdaichain.com/fake/example/url/xdai.svg",
"https://xdaichain.com/fake/example/url/xdai.png"
],
"nativeCurrency": {
"name": "xDAI",
"symbol": "xDAI",
"decimals": 18
},
"blockExplorerUrls": [
"https://blockscout.com/poa/xdai/"
]
}
]
});

Result

"null"

Params

AddEthereumChainParameter

blockExplorerUrls
iconUrls
NativeCurrency
rpcUrls

Request

await window.ethereum.request({
"method": "wallet_addEthereumChain",
"params": [
null
]
});