This method returns the current network ID on the Somnia network. The network ID is typically the same as the chain ID (5031 for Mainnet, 50312 for Testnet) and is used for network identification.
bashcurl -X POST https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "net_version",
"params": []
}'
javascriptconst axios = require('axios');
const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
id: 'getblock.io',
method: 'net_version',
params: []
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));
pythonimport requests
import json
url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
payload = {
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "net_version",
"params": []
}
response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
print(response.json())
rustuse reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "net_version",
"params": []
});
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&payload)
.send()
.await?;
let result: serde_json::Value = response.json().await?;
println!("{:#?}", result);
Ok(())
}
javascriptconst { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
const network = await provider.getNetwork();
console.log(network.chainId);
javascriptimport { createPublicClient, http } from 'viem';
import { somnia } from 'viem/chains';
const client = createPublicClient({
chain: somnia,
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
const chainId = await client.getChainId();
console.log(chainId);