[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThis page outlines how to interact with Ethereum blockchain nodes via their APIs, including JSON-RPC, Beacon node RPC, and WebSocket.\u003c/p\u003e\n"],["\u003cp\u003eTo access any of the node APIs, you will need both an API key and the node endpoint URL, which can be obtained by following the instructions within the "using blockchain nodes" guide.\u003c/p\u003e\n"],["\u003cp\u003eThe document provides examples of how to call methods using JSON-RPC to query the execution client, including how to call the \u003ccode\u003eeth_getBlockByNumber()\u003c/code\u003e method with a curl command and the structure of the request object.\u003c/p\u003e\n"],["\u003cp\u003eYou can also connect to the Ethereum consensus client endpoint through Beacon node RPC, to query the state of a validator and examples of the curl commands and their response.\u003c/p\u003e\n"],["\u003cp\u003eBlockchain Node Engine enables WebSocket connections to subscribe to real-time data feeds from the execution client, and it also exposes metrics for both the execution and beacon clients, which can be fetched via curl.\u003c/p\u003e\n"]]],[],null,["# Using Ethereum blockchain nodes\n\nThis page describes how to call the Ethereum node API.\nBefore you can access the Ethereum blockchain node, you will need to know the\nAPI key and node endpoint URL. Follow the\n[using blockchain nodes](/blockchain-node-engine/docs/using-nodes) guide\nto determine these, if you have not already done so.\n\nJSON-RPC\n--------\n\nThis section describes querying an Ethereum blockchain node's\n[JSON-RPC API](#json-el).\n\n### Example execution client RPC\n\nYou can query the execution client ([Geth](https://launchpad.ethereum.org/en/geth)\nfor full nodes or [Erigon](https://launchpad.ethereum.org/en/erigon)\nfor archive nodes) via JSON-RPC. See\n[Ethereum API specification](https://ethereum.github.io/execution-apis/api-documentation/)\nfor the generic JSON-RPC specification, or the [Geth RPC documentation](https://geth.ethereum.org/docs/interacting-with-geth/rpc) for Geth-specific documentation.\n\nFor example, to call the `eth_getBlockByNumber()` method: \n\n curl -H POST \\\n -H \"X-goog-api-key: \u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"id\":1,\n \"jsonrpc\":\"2.0\",\n \"method\": \"eth_getBlockByNumber\",\n \"params\": [\"0x1\", true]\n }' \\\n http://\u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e\n\nWhere:\n\n- `id` is an identifier set by the client--the originator of the request. For example, `1`.\n- `jsonrpc` is the JSON-RPC version. For example, `2.0`.\n- `method` is the name of the method. For example, `eth_getBlockByNumber`.\n- `params` are values to be used with `method`.\n- \u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e is the address returned in [Get the blockchain node URLs](/blockchain-node-engine/docs/using-nodes#get-urls). For example, `json-rpc.ejp4j0b1rdiq06p8lxksd5z25.blockchainnodeengine.com`.\n- \u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e is the key you created in [Create an API key](/blockchain-node-engine/docs/using-nodes#create-api-key).\n\nSee\n[JSON-RPC2.0 Specification](https://www.jsonrpc.org/specification)\nfor more information on the format of the Request object.\n\nHere's a sample response to the above command: \n\n {\n \"id\" : 1,\n \"jsonrpc\" : \"2.0\",\n \"result\" : {\n \"difficulty\" : \"0x3ff800000\",\n \"extraData\" : \"0x476574682f76312e302e302f6c696e75782f676f312e342e32\",\n \"gasLimit\" : \"0x1388\",\n \"gasUsed\" : \"0x0\",\n \"hash\" : \"0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6\",\n \"logsBloom\": \"0x0000000000000000000000000000000000000\",\n \"miner\" : \"0x05a56e2d52c817161883f50c441c3228cfe54d9f\",\n \"mixHash\" : \"0x969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f59\",\n \"nonce\" : \"0x539bd4979fef1ec4\",\n \"number\" : \"0x1\",\n \"parentHash\" : \"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3\",\n \"receiptsRoot\" : \"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\n \"sha3Uncles\" : \"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\n \"size\" : \"0x219\",\n \"stateRoot\" : \"0xd67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3\",\n \"timestamp\" : \"0x55ba4224\",\n \"totalDifficulty\" : \"0x7ff800000\",\n \"transactions\" : [],\n \"transactionsRoot\" : \"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\n \"uncles\" : []\n }\n }\n\n### Beacon node RPC\n\nBlockchain Node Engine also exposes the Ethereum consensus client endpoint.\nFor example to request the state of the validator at slot `1`: \n\n curl \\\n -H \"X-goog-api-key: \u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\" \"Content-Type: application/json\" \\\n 'http://beacon.\u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e/eth/v1/beacon/states/head/validators/1'\n\nYou may also provide your API key as an HTTP header instead of\na query parameter. The following query is equivalent: \n\n curl \\\n -H \"Content-Type: application/json\" \\\n 'http://beacon.\u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e/eth/v1/beacon/states/head/validators/1?key=\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e'\n\nFurther Explained:\n\n- \u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e is the address returned in [Get the blockchain node URLs](/blockchain-node-engine/docs/using-nodes#get-urls).\n- \u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e is the key you created in [Create an API key](/blockchain-node-engine/docs/using-nodes#create-api-key).\n\nHere's a sample response to the above command: \n\n {\n \"execution_optimistic\": false,\n \"data\": {\n \"index\": \"1\",\n \"balance\": \"36835614902\",\n \"status\": \"active_ongoing\",\n \"validator\": {\n \"pubkey\": \"0x1234abcd\",\n \"withdrawal_credentials\": \"0x1234abcd\",\n \"effective_balance\": \"32000000000\",\n \"slashed\": false,\n \"activation_eligibility_epoch\": \"0\",\n \"activation_epoch\": \"0\",\n \"exit_epoch\": \"18446744073709551615\",\n \"withdrawable_epoch\": \"18446744073709551615\"\n }\n }\n }\n\nWebSocket\n---------\n\nTo subscribe to data feeds rather than poll for data, you can use the\nWebSocket API of the blockchain node's execution client.\n| **Note:** Clients using WebSockets must be able to handle loss of the connection. It is strongly recommended that clients track the subscriptions they have on a WebSocket connection and automatically resubscribe to those events if the connection is lost.\n\nFor example, to subscribe to new chain heads: \n\n wscat -c wss://ws.\u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e?key=\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\n Connected (press CTRL+C to quit)\n \u003e {\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"newHeads\"]}\n\nThe execution client will respond with an identifier for the subscription,\nsuch as: \n\n {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0xf47df962ae9ba250ba9e9fb239b6894f\"}\n\nThereafter the client will send details of each new chain head block as it\noccurs. Here's a sample event from the above subscription: \n\n {\n \"jsonrpc\" : \"2.0\",\n \"method\" : \"eth_subscription\",\n \"params\" : {\n \"result\" : {\n \"baseFeePerGas\" : \"0x4bdc620b8\",\n \"difficulty\" : \"0x0\",\n \"extraData\" : \"0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465\",\n \"gasLimit\" : \"0x1c9c380\",\n \"gasUsed\" : \"0xe24dae\",\n \"hash\" : \"0xbde840749c4d9086d17d66079d5f7d3d568ed4572329691e5b4a70f44a551816\",\n \"logsBloom\": \"0x0000000000000000000000000000000000000\",\n \"miner\" : \"0xb4c9e4617a16be36b92689b9e07e9f64757c1792\",\n \"mixHash\" : \"0xf68eb0b3ec50e1543de1cc7f09c7735ba20fa252124511756857078a3ff9a7cf\",\n \"nonce\" : \"0x0000000000000000\",\n \"number\" : \"0x109e280\",\n \"parentHash\" : \"0x54f78faba9fde0d15d7a9d6b80c4569435c7fdc5f1fef3255110373b66ce14de\",\n \"receiptsRoot\" : \"0x876bcb5772f8597fee4b063c57b7a51209eb428034efabf4cdf39a46901681b4\",\n \"sha3Uncles\" : \"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\n \"stateRoot\" : \"0xfc5daf9608c8f2b9944bcfe0b9182148d85b1a6ad4dc52d3eb522dd02687c7e0\",\n \"timestamp\" : \"0x647fd287\",\n \"transactionsRoot\" : \"0x0acaef87e4609ea6075d88fdd404b3fbd25d796af9044522beefd3c708d37af8\",\n \"withdrawalsRoot\" : \"0x7adfc670253572678769e7d80db8c4c94b5d14d4e014274f39b679fdb5e72d98\"\n },\n \"subscription\" : \"0xf47df962ae9ba250ba9e9fb239b6894f\"\n }\n }\n\nMetrics\n-------\n\nEthereum nodes provide a number of metrics on the operational state of the node.\nTypically these would be consumed by a tool such as\n[Prometheus](https://prometheus.io/) or\n[Grafana](https://grafana.com/).\n| **Tip:** Blockchain Node Engine writes metrics into [Cloud Monitoring](/stackdriver) without requiring any additional infrastructure.\n\nTo fetch the metrics exposed by a beacon client you can use a command such\nas: \n\n curl https://bc-mc.\u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e/metrics/prometheus?key=\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\n\nThis produces an output similar to the following: \n\n # HELP async_tasks_count Total number of async tasks spawned using spawn\n # TYPE async_tasks_count gauge\n async_tasks_count{async_task_count=\"addr_broadcast\"} 0\n async_tasks_count{async_task_count=\"beacon_node\"} 0\n async_tasks_count{async_task_count=\"beacon_processor_manager\"} 1\n async_tasks_count{async_task_count=\"beacon_processor_reprocess_queue\"} 1\n async_tasks_count{async_task_count=\"beacon_processor_worker\"} 0\n async_tasks_count{async_task_count=\"discv5\"} 4\n async_tasks_count{async_task_count=\"el_fork_choice_update\"} 0\n async_tasks_count{async_task_count=\"eth1\"} 1\n ...\n\nThere are separate metrics endpoints for the execution client and beacon client.\nFor the execution client these are typically prefixed `ec-mc` and for the\nbeacon client they are typically prefixed `bc-mc` (as in the example above).\n| **Note:** The path for execution client metrics is `/debug/metrics/prometheus`, for example `https://ec-mc.`\u003cvar translate=\"no\"\u003eYOUR_NODES_URL\u003c/var\u003e`/debug/metrics/prometheus?key=`\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\n\nYou can read more about metrics from each client software at:\n\n- [Geth](https://geth.ethereum.org/docs/monitoring/metrics)\n- [Lighthouse](https://lighthouse-book.sigmaprime.io/advanced_metrics.html)"]]