Skip to main content

parse_custom_error

Function parse_custom_error 

Source
pub fn parse_custom_error(output: &[u8]) -> Option<String>
Expand description

Parse custom error output from a failed transaction

Handles two main types of errors:

  1. Error(string) - Standard revert with message (selector: 0x08c379a0)
  2. Panic(uint256) - Solidity panic with error code (selector: 0x4e487b71)

§Arguments

  • output - Raw error output bytes from the failed transaction

§Returns

  • Some(String) - Decoded error message or panic reason
  • None - If the error format is not recognized or cannot be decoded

§Example

use revm_trace::utils::error_utils::parse_custom_error;
use alloy::primitives::hex;
let error_output = hex::decode("08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000014496e73756666696369656e742062616c616e636500000000000000000000000000").unwrap();
let error_message = parse_custom_error(&error_output);
assert_eq!(error_message, Some("Insufficient balance".to_string()));