Solidity Custom Errors and JSON-RPC Clients: Preserving Failed-Deployment Revert Data Across the Boundary
0 reputation · 02 Dec 2022, 21:22 UTC
0 reputation · 02 Dec 2022, 21:22 UTC
An application integrating Solidity contracts with off-chain EVM/JSON-RPC clients needs to classify failed deployments, but a reverted constructor produces a failed receipt and no ordinary logs, so log-based diagnostics miss the reason. Custom errors encode a revert payload with a selector and ABI-encoded arguments, but clients vary in exposing raw bytes or decoded reasons.
When a client lacks the custom-error ABI, it may return only a selector or generic failure. An absent payload does not confirm no revert, since gas exhaustion or retrieval limits can also leave no reason. Constructor and runtime reverts share the same channel, so decoded errors cannot be assumed to originate in constructor code. Because receipt status, transaction-error fields, and error formatting vary across clients and versions, the exact representation should be verified against the production toolchain.
How should an integration preserve raw revert bytes and decode them separately while recording chain, transaction hash, and client context? What fallback classification is appropriate when decoding fails or no payload is exposed? How can deployment tooling distinguish a deliberate constructor revert from other execution failures without assuming a single client API shape?
35775 reputation · 03 Dec 2022, 08:37 UTC
To preserve a failed‑deployment revert across the JSON‑RPC boundary you should:
error or revertReason field).With that context you can decode the payload separately and classify the failure.
eth_getTransactionReceipt or an enhanced provider endpoint).ethers.js or web3.js to decode:
const iface = new ethers.utils.Interface(["error MyError(uint256)""]);
const decoded = iface.parseError(rawBytes);
status === 0 and logs.length === 0 and rawBytes.length > 0, label as deliberate constructor revert.status === 0 and rawBytes.length === 0, label as unknown failure (possible gas exhaustion or client truncation).To fine‑tune the fallback logic, could you confirm whether your JSON‑RPC client returns the raw revert bytes in a field such as error or revertReason, or if it only exposes a selector? This detail may change the decoding strategy.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.