> loading_
# How to handle the new `eth_getProof` key limit
// This example demonstrates how to adapt your application to the new key limit
// by batching requests for `eth_getProof`.
// Assume this is the new limit imposed by the GOAT Network node.
const PROOF_KEY_LIMIT = 128;
// Your application might request proofs for a large number of storage slots.
const largeNumberOfStorageKeys = Array.from({ length: 300 }, (_, i) => `0x${i.toString(16).padStart(64, '0')}`);
const contractAddress = '0xDECAF9CD2367cdbb726E904cD6397eDFcAe6068D'; // Example address
const blockNumber = 'latest';
// A mock `getProof` function to simulate the client call.
// In a real app, you'd use a library like viem or ethers.js.
async function mockGetProof(address, keys, block) {
console.log(`Fetching proof for ${keys.length} keys...`);
if (keys.length > PROOF_KEY_LIMIT) {
throw new Error('Proof request exceeds key limit');
}
return { success: true, keys: keys.length };
}
async function getBatchedProofs(address, keys, block) {
// 1. Check if the number of keys exceeds the node's limit.
if (keys.length <= PROOF_KEY_LIMIT) {
console.log("Request is within the limit. Making a single call.");
return mockGetProof(address, keys, block);
}
// 2. If it exceeds the limit, split the keys into smaller chunks.
console.log(`Request exceeds key limit of ${PROOF_KEY_LIMIT}. Batching requests...`);
const allProofData = [];
for (let i = 0; i < keys.length; i += PROOF_KEY_LIMIT) {
const chunk = keys.slice(i, i + PROOF_KEY_LIMIT);
console.log(`Processing batch ${Math.floor(i / PROOF_KEY_LIMIT) + 1}...`);
// 3. Make a separate `eth_getProof` call for each chunk.
try {
const proof = await mockGetProof(address, chunk, block);
allProofData.push(proof);
} catch (error) {
console.error(`Error fetching batch: ${error.message}`);
// Handle error for the individual batch as needed.
}
}
console.log("All batches processed.");
// 4. In a real application, you would merge the proof data here.
return allProofData;
}
// Execute the function to see the batching logic in action.
getBatchedProofs(contractAddress, largeNumberOfStorageKeys, blockNumber);