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

bundlerClient.prepareUserOperation getBundlerError.ts expose data #3149

Open
1 task done
841660202 opened this issue Dec 20, 2024 · 5 comments
Open
1 task done

bundlerClient.prepareUserOperation getBundlerError.ts expose data #3149

841660202 opened this issue Dec 20, 2024 · 5 comments
Labels
needs reproduction Misc: Needs Reproduction

Comments

@841660202
Copy link

841660202 commented Dec 20, 2024

Check existing issues

Viem Version

latest

Current Behavior

-32521 Example

{
    "jsonrpc": "2.0",
    "id": 3,
    "error": {
        "code": -32521,
        "message": "execution reverted",
        "data": {
            "revertData": "0xcf47918100000000000000000000000000000000000000000000000007e9e499c7a4dbe800000000000000000000000000000000000000000000000007e9e499c7a4dbe1"
        }
    }
}
{
    "jsonrpc": "2.0",
    "id": 459,
    "error": {
        "code": -32521,
        "message": "execution reverted",
        "data": {
            "revertData": "0x"
        }
    }
}

return new ExecutionRevertedError({

export class ExecutionRevertedError extends BaseError {

No data is exposed

Expected Behavior

I want to expose the revertData field in the error response so that I can parse it using the Ethereum Signature Database. This will allow me to extract meaningful information and provide clear feedback to the user.

If I have data I will

import { decodeFunctionData, parseAbi } from 'viem';
import { describe, test } from 'vitest'

async function handleRevertData(result) {
  try {
    // Step 2: Extract the revertData prefix
    const revertData = result.error.data.revertData;
    const hexSignature = revertData.slice(0, 10);

    // Step 3: Fetch the signature from the API
    const response = await fetch(`https://www.4byte.directory/api/v1/signatures/?hex_signature=${hexSignature}`);
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    const apiData = await response.json();

    // Step 4: Extract the text signature from the API response
    if (apiData.count === 0) {
      throw new Error('Signature not found');
    }
    const textSignature = apiData.results[0].text_signature;

    // Step 5: Parse the ABI
    // @ts-ignore
    const abi = parseAbi([`function ${textSignature}`]);

    // Step 6: Decode the function data
    const decodedData = decodeFunctionData({
      abi,
      data: revertData,
    });

    // Step 7: Return decoded data

    return decodedData

  } catch (error) {
    console.error('Error handling revert data:', error);
  }
}



describe('chains', () => {
  test('default', async () => {
    // Example usage
    const result = {
      "jsonrpc": "2.0",
      "id": 3,
      "error": {
          "code": -32521,
          "message": "execution reverted",
          "data": {
              "revertData": "0xcf47918100000000000000000000000000000000000000000000000007e9e499c7a4dbe800000000000000000000000000000000000000000000000007e9e499c7a4dbe1"
          }
      }
    };

    const decodedData = await handleRevertData(result);
    console.log('Decoded Data:', decodedData);

  })
})

out

image

Steps To Reproduce

No response

Link to Minimal Reproducible Example

No response

Anything else?

No response

@841660202 841660202 changed the title bundlerClient.prepareUserOperation getBundlerError.ts expose -32521 data bundlerClient.prepareUserOperation getBundlerError.ts expose data Dec 20, 2024
@jxom jxom closed this as completed in ca0e956 Dec 22, 2024
@841660202
Copy link
Author

841660202 commented Dec 23, 2024

[email protected]

Ques

If revert occurs, get this data after estimateUserOperationGas ends. But I still can't get the raw data here

throw getUserOperationError(error as BaseError, {

image

Bebug viem

image image

@jxom

@jxom
Copy link
Member

jxom commented Dec 23, 2024

Screenshots are not helpful. Please open a new issue with a minimal reproducible example.

@jxom jxom added the needs reproduction Misc: Needs Reproduction label Dec 23, 2024
Copy link
Contributor

Hello @841660202.

Please provide a minimal reproduction using StackBlitz, TypeScript Playground (for type issues), or a separate minimal GitHub repository.

Minimal reproductions are required as they save us a lot of time reproducing your config/environment and issue, and allow us to help you faster.

Once a minimal reproduction is added, a team member will confirm it works, then re-open the issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2024
@841660202
Copy link
Author

841660202 commented Dec 23, 2024

@jxom
Copy link
Member

jxom commented Dec 23, 2024

Thank you.

@jxom jxom reopened this Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction Misc: Needs Reproduction
Projects
None yet
Development

No branches or pull requests

2 participants