Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for decoding custom errors from JSON-RPC reverts #122

Closed
zerosnacks opened this issue Jul 24, 2024 · 4 comments · Fixed by #127
Closed

Add example for decoding custom errors from JSON-RPC reverts #122

zerosnacks opened this issue Jul 24, 2024 · 4 comments · Fixed by #127
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@zerosnacks
Copy link
Member

zerosnacks commented Jul 24, 2024

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?

@zerosnacks zerosnacks added enhancement New feature or request good first issue Good for newcomers labels Jul 24, 2024
@PraneshASP
Copy link
Contributor

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
Copy link
Member Author

I think we can just add this as an example

@PraneshASP
Copy link
Contributor

Looks like the change (as_decoded_error()) hasn't been released/published yet. will add this after the next release of alloy.

@zerosnacks
Copy link
Member Author

https://github.com/alloy-rs/alloy/releases/tag/v0.2.1 was just released, removing the blocked tag :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants