Retrieve account and storage values, including Merkle proof, using eth_getProof. Essential for verifying on-chain data integrity and enabling trusted responses in IoT and mobile applications.
This method returns the account and storage values of a specified account, including the Merkle proof.
The eth_getProof method is part of the Ethereum JSON RPC Core API, used to interact with Ethereum nodes. The eth_getProof method is particularly useful for scenarios where IoT devices or mobile apps, which are unable to run light clients, need to verify responses from untrusted sources using a trusted block hash.
The eth_getProof RPC Ethereum method is an essential tool for verifying on-chain data integrity, enabling the retrieval of account details and storage proof data. This allows developers to create applications that can validate the state of specific accounts and their corresponding storage slots, ensuring accurate and trustworthy information. The method also facilitates the retrieval of proof data via different API endpoints, making it highly versatile.
Supported Networks
Ethereum eth_getProof RPC method supports the following network types:
Mainnet
Testnet: Sepolia, Holesky
Parameters
DATA: The 20-byte address of the account or contract for which to retrieve proof data.
ARRAY: An array of 32-byte storage keys to generate proofs for.
QUANTITY | TAG: An integer representing a block number or one of the string tags latest, earliest, or pending, as described in Block Parameter
Request
URL (API Endpoint)
https://go.getblock.io/<ACCESS-TOKEN>/
To make a request, send a JSON object with the jsonrpc, method, and params fields. Below is an example of how to make a request using curl:
wscat -c wss://eth.getblock.io/YOUR-API-KEY/ # wait for connection and send the request body {"jsonrpc":"2.0","method":"eth_getProof","params": ["0x0a8156e7ee392d885d10eaa86afd0e323afdcd95", ["0xc48fb64230a82f65a08e7280bd8745e7fea87bc7c206309dee32209fe9a985f7"],"latest"],"id":"getblock.io"}
Response
The server responds with a JSON object containing the proof details of the specified account and storage keys. Below is an example of a typical response:
accountProof: The Merkle proof for the account, represented as an array of strings.
address: The address of the account or contract for which the proof was requested.
balance: The current balance of the account in Wei.
codeHash: The hash of the code of the account.
nonce: The nonce of the account, representing the number of transactions sent.
storageHash: The storage root hash of the account.
storageProof: An array of storage proofs for the specified storage keys, including the key, proof, and value.
Use Case
The eth_getProof method is particularly useful for verifying on-chain data, especially in cases where applications need to validate the state of a specific account or storage slot. This is crucial for IoT devices, mobile apps, and other lightweight clients that cannot run full or light nodes. By using the eth_getProof RPC method, these clients can verify the integrity of data received from untrusted sources. In case of an eth_getProof error, developers should check the provided parameters and ensure that the block hash or address is correct. Additionally, by using different endpoints, developers can access the method across various environments.
The eth_getProof method is also useful for transaction tracking. Developers can verify specific transactions associated with an account by retrieving the proof and cross-checking the values.
Code Example
Below is an eth_getProof example demonstrating how to make a request programmatically using Python.You can also make requests to the eth_getProof method programmatically using Python. Below is an example using the requests library:
import requestsimport json# Define the API URL and access tokenurl ='https://go.getblock.io/<ACCESS-TOKEN>/'headers ={'Content-Type':'application/json'}# Prepare the request datadata ={"jsonrpc":"2.0","method":"eth_getProof","params": ["0x0a8156e7ee392d885d10eaa86afd0e323afdcd95", ["0xc48fb64230a82f65a08e7280bd8745e7fea87bc7c206309dee32209fe9a985f7" ],"latest" ],"id":"getblock.io"}# Send the POST requestresponse = requests.post(url, headers=headers, data=json.dumps(data))# Parse the JSON responseresponse_data = response.json()# Print the resultprint(json.dumps(response_data, indent=4))
constaxios=require('axios');// Replace <ACCESS-TOKEN> with your actual API keyconsturl='https://go.getblock.io/<ACCESS-TOKEN>/';// Request payloadconstrequestBody= { jsonrpc:'2.0', method:'eth_getProof', params: ['0x0a8156e7ee392d885d10eaa86afd0e323afdcd95',// Address ['0xc48fb64230a82f65a08e7280bd8745e7fea87bc7c206309dee32209fe9a985f7'],// Storage keys array'latest',// Block tag ], id:'getblock.io',};// Axios POST requestaxios.post(url, requestBody, { headers: {'Content-Type':'application/json', }, }).then((response) => {console.log('Proof Response:',response.data.result); }).catch((error) => {console.error('Error fetching proof:',error.message); });
This Python script sends a request to the eth_getProof method and prints the returned proof information. Make sure to replace <ACCESS-TOKEN> with your actual API token.
The Web3 eth_getProof method can also be used in Web3 libraries for Ethereum, providing an interface to access and verify blockchain data for various use cases, including transaction tracking, account verification, and data validation.