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

[Feature] Get abi error data from an error response on call / send transaction #787

Closed
rplusq opened this issue May 27, 2024 · 2 comments · Fixed by #1098
Closed

[Feature] Get abi error data from an error response on call / send transaction #787

rplusq opened this issue May 27, 2024 · 2 comments · Fixed by #1098
Labels
enhancement New feature or request

Comments

@rplusq
Copy link

rplusq commented May 27, 2024

Component

contract

Describe the feature you would like

Right now, assuming I have a contract Foo with a function bar, if it has an error, I have to do a lot of parsing / handling to get the abi error. I would like to have a more convenient function to handle this.

Example of how I'm doing it right now:

sol!(
    #[allow(missing_docs)]
    #[sol(rpc)]
    Foo,
    "abis/Foo.json"
);

let foo_contract = Foo::new(FOO_ADDRESS, &provider);

let tx_receipt = match foo_contract
        .bar()
        .from(signer)
        .send()
        .await
    {
        Ok(result) => result.get_receipt().await?,
        Err(error) => match error {
            Error::TransportError(TransportError::ErrorResp(err)) => {
                let data = err.data.unwrap_or_default();
                let data = data.get().trim_matches('"');
                let data = Bytes::from_str(data)?;
                let decoded_error = Foo::FooErrors::abi_decode(&data, true)?;

            }
            _ => {
                return Err(eyre::eyre!(
                    "Received TransportError with data: {:?}",
                    eyre::eyre!(error)
                ))
            }
        },
    };

Additional context

No response

@rplusq rplusq added the enhancement New feature or request label May 27, 2024
@prestwich
Copy link
Member

related logic from ethers-rs here

we essentially need to

  • check if the response is an error response
  • deserialize error contents into serde_json::Value
  • spelunk to find revert data
  • attempt to decode that revert data as a MyContract::MyContractErrors type
  • return that data as a raw revert if deserialization failed

@rplusq
Copy link
Author

rplusq commented Jul 4, 2024

Starting to work on this

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

Successfully merging a pull request may close this issue.

4 participants