Required roles
To get the permissions that
you need to view API keys,
ask your administrator to grant you the
API Key Viewer (roles/serviceusage.apiKeysViewer
)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Using the RPC endpoint
In the Google Cloud console, go to the Blockchain RPC page.
From the console, copy the JSON-RPC endpoint that matches the
network
andlocation
combination you need.Now you can begin making requests. A full list of all the RPC methods available are listed in the RPC API reference documentation. Our example request calls the
eth_blockNumber
method.
curl -X POST -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method":
"eth_blockNumber",
"params": []}' \
JSON_RPC_ENDPOINT
Where:
- JSON_RPC_ENDPOINT is an endpoint you copied from the console. This endpoint includes a default API key that has been automatically created. You can manage all of your keys on the Credentials page.
After executing this curl request, you should see a response like:
{"jsonrpc":"2.0","id":1,"result":"0x13acb8d"}
Using WebSocket subscriptions
WebSocket support is also enabled for Blockchain RPC endpoints. This example uses the wscat open source project.
In the Google Cloud console, go to the Blockchain RPC page.
From the console, copy the WebSocket endpoint that matches the
network
andlocation
combination you need.Now you can begin making requests.
wscat -c WS_ENDPOINT
Where:
- WS_ENDPOINT is a WebSocket endpoint from the console.
Subscribe to new block headers:
{"id":1,"jsonrpc":"2.0","method":"eth_subscribe","params":["newHeads"]}
You'll start receiving messages for each new block header.