eth_chainId
Returns the chain ID used for transaction signing on Moonriver.
Why Moonriver? Build on the Moonbeam canary network on Kusama for real-world testing of EVM dApps with Moonbeam code ships here first, full EVM compatibility on Kusama, 80% fee burn mechanism, and XCM cross-chain messaging.
Use Cases#
The eth_chainId method is essential for:
- Transaction signing - Ensure transactions are signed for the correct network
- Network verification - Confirm connection to the expected chain
- Multi-chain apps - Handle different networks programmatically
- Wallet integration - Validate network before transactions
Parameters#
This method accepts no parameters.
Request#
{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}
Returns#
| Type | Description |
|---|---|
QUANTITY | Chain ID in hexadecimal |
Response#
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1"
}
Code Examples#
- cURL
- JavaScript
- Python
- Go
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}'
import { JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('');
const network = await provider.getNetwork();
console.log('Chain ID:', network.chainId);
// Verify network before transaction
async function verifyNetwork(expectedChainId) {
const network = await provider.getNetwork();
if (network.chainId !== BigInt(expectedChainId)) {
throw new Error(`Wrong network. Expected ${expectedChainId}, got ${network.chainId}`);
}
return true;
}
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(''))
chain_id = w3.eth.chain_id
print(f'Chain ID: {chain_id}')
# Verify network
def verify_network(expected_chain_id):
chain_id = w3.eth.chain_id
if chain_id != expected_chain_id:
raise ValueError(f'Wrong network. Expected {expected_chain_id}, got {chain_id}')
return True
package main
import (
"context"
"fmt"
"log"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("")
if err != nil {
log.Fatal(err)
}
chainID, err := client.ChainID(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Chain ID: %d\n", chainID)
}
Related Methods#
net_version- Get network versioneth_syncing- Check sync status