{"record":{"id":"db0310df023f74ff","repo":"shardeum/shardeum","slug":"failed-to-retrieve-eth-getblockbyhash","errorCode":null,"errorMessage":"Failed to retrieve eth_getBlockByHash","messagePattern":"Failed to retrieve eth_getBlockByHash","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"src/index.ts","lineNumber":1544,"sourceCode":"    }\n  })\n\n  shardus.registerExternalGet('eth_getBlockByHash', externalApiMiddleware, async (req, res) => {\n    try {\n      /* eslint-disable security/detect-object-injection */\n      let blockHash = req.query.blockHash as string\n      if (blockHash === 'latest') blockHash = readableBlocks[latestBlock].hash\n      else if (blockHash.length !== 66 || !isHexString(blockHash)) {\n        res.json({ error: 'Invalid block hash' })\n        return\n      }\n      if (ShardeumFlags.VerboseLogs) console.log('Req: eth_getBlockByHash', blockHash)\n      const blockNumber = blocksByHash[blockHash]\n      res.json({ block: readableBlocks[blockNumber] })\n      /* eslint-enable security/detect-object-injection */\n    } catch (err) {\n      if (ShardeumFlags.VerboseLogs) console.log('Failed to retrieve eth_getBlockByHash: ', err)\n      res.status(500).json({ error: 'Failed to retrieve eth_getBlockByHash' })\n    }\n  })\n\n  shardus.registerExternalGet('stake', async (req, res) => {\n    try {\n      const stakeRequiredUsd = AccountsStorage.cachedNetworkAccount.current.stakeRequiredUsd\n      const stakeRequired = scaleByStabilityFactor(stakeRequiredUsd, AccountsStorage.cachedNetworkAccount)\n      if (ShardeumFlags.VerboseLogs) console.log('Req: stake requirement', _readableSHM(stakeRequired))\n\n      const response = {\n        stakeRequired: {\n          dataType: 'bi',\n          value: stakeRequired.toString(16).padStart(16, '0'),\n        },\n        stakeRequiredUsd: {\n          dataType: 'bi',\n          value: stakeRequiredUsd.toString(16).padStart(16, '0'),\n        },","sourceCodeStart":1526,"sourceCodeEnd":1562,"githubUrl":"https://github.com/shardeum/shardeum/blob/0c454caf067f7b896569eabdd5f47cb8b61738b3/src/index.ts#L1526-L1562","documentation":"The eth_getBlockByHash external endpoint returns this 500 when looking up a block by its hash throws. It maps blockHash -> blockNumber via the blocksByHash table, then indexes readableBlocks with that number; if the hash key is absent the lookup yields undefined (usually not a throw), so an actual 500 means something else in the try block failed.","triggerScenarios":"Calling GET /eth_getBlockByHash with a malformed hash string, a hash containing characters that break object-key injection guards or internal lookups, or an exception while serializing the found block for the response.","commonSituations":"Explorers or indexers querying by transaction/block hashes the node does not have (post-clean networks), passing 0x-prefixed vs non-prefixed hashes inconsistently, or hitting the endpoint mid-sync.","solutions":["Verify the hash is a valid 66-char hex block hash and exists on this network","Enable ShardeumFlags.VerboseLogs to capture the underlying error logged as 'Failed to retrieve eth_getBlockByHash'","Check that readableBlocks/blocksByHash are populated (node synced); restart the node if internal maps are empty"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const BLOCK_HASH_RE = /^0x[0-9a-fA-F]{64}$/\nif (!BLOCK_HASH_RE.test(blockHash)) throw new Error('malformed block hash')","typeGuard":"function isBlockHash(v: unknown): v is `0x${string}` {\n  return typeof v === 'string' && /^0x[0-9a-fA-F]{64}$/.test(v)\n}","tryCatchPattern":"try {\n  const r = await fetch(`/eth_getBlockByHash?hash=${blockHash}`)\n  if (r.status === 500) return null // treat as not-found on this node\n  return r.json()\n} catch { return null }","preventionTips":["Normalize hashes to lowercase 0x-prefixed 66-char form before querying","Verify the hash was produced on the same network (post-clean hashes disappear)","Fall back to eth_getBlockByNumber if hash lookup fails"],"tags":["http","eth-getblockbyhash","block-query","shardeum-external-api"],"backgroundTag":"rpc-block-not-found","analyzedSha":"0c454caf067f7b896569eabdd5f47cb8b61738b3","analyzedAt":"2026-08-28T11:43:29.666Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}