curl --request POST \
--url https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}'
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x3e6"
}
Returns the chain ID of the currently connected blockchain network. This method is essential for identifying the specific blockchain network and ensuring transaction compatibility.
curl --request POST \
--url https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}'
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x3e6"
}
eth_chainId
JSON-RPC method returns the chain ID of the currently connected blockchain network. This method is fundamental for identifying the specific blockchain network, ensuring transaction compatibility, and implementing network-specific logic in applications.
params
field should be an empty array.
result
— The chain ID as a hexadecimal string (e.g., “0x3e6” which equals 998 in decimal for Hyperliquid)// Get Hyperliquid chain ID
const getChainId = async () => {
const response = await fetch('https://hyperliquid-mainnet.core.chainstack.com/YOUR_ENDPOINT/evm', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_chainId',
params: [],
id: 1
})
});
const data = await response.json();
const chainId = parseInt(data.result, 16);
return {
hex: data.result,
decimal: chainId,
network: chainId === 998 ? 'Hyperliquid Mainnet' : 'Unknown'
};
};
// Verify network connection
const verifyNetwork = async () => {
const { decimal: chainId, network } = await getChainId();
if (chainId !== 998) {
throw new Error(`Expected Hyperliquid Mainnet (998), got ${network} (${chainId})`);
}
console.log(`Connected to ${network}`);
return true;
};
// Usage
verifyNetwork()
.then(() => console.log('Network verified'))
.catch(error => console.error('Network verification failed:', error));
curl -X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' \
https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm
eth_chainId
method is essential for applications that need to:
Successful response with the chain ID
The response is of type object
.
Was this page helpful?