Add example for decoding custom errors from JSON-RPC reverts
zerosnacks opened this issue ยท 4 comments
zerosnacks commented
Related: alloy-rs/alloy#1098 + https://github.com/alloy-rs/alloy/pull/1098/files
See:
fn custom_error_decoding() {
sol!(
library Errors {
error SomeCustomError(uint256 a);
}
);
let json = r#"{"code":3,"message":"execution reverted: ","data":"0x810f00230000000000000000000000000000000000000000000000000000000000000001"}"#;
let payload: ErrorPayload = serde_json::from_str(json).unwrap();
let Errors::ErrorsErrors::SomeCustomError(value) =
payload.as_decoded_error::<Errors::ErrorsErrors>(false).unwrap();
assert_eq!(value.a, U256::from(1));
}
Likely best placed in the contracts
as jsonrpc_error_decoding
?
PraneshASP commented
The attached code snippet looks good enough for the example. can we just add the same as example or do you prefer a more complex one?
zerosnacks commented
I think we can just add this as an example
PraneshASP commented
Looks like the change (as_decoded_error()
) hasn't been released/published yet. will add this after the next release of alloy.
zerosnacks commented
https://github.com/alloy-rs/alloy/releases/tag/v0.2.1 was just released, removing the blocked
tag :)