Skip to content

support UnknownRpcError in getSenderAddress #239

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions packages/permissionless/actions/public/getSenderAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
RpcRequestError,
type Transport,
concat,
decodeErrorResult
decodeErrorResult,
UnknownRpcError
} from "viem"

import { simulateContract } from "viem/actions"
Expand Down Expand Up @@ -136,7 +137,8 @@ export const getSenderAddress = async <
(err) =>
err instanceof ContractFunctionRevertedError ||
err instanceof RpcRequestError ||
err instanceof InvalidInputRpcError
err instanceof InvalidInputRpcError ||
err instanceof UnknownRpcError
)

if (revertError instanceof ContractFunctionRevertedError) {
Expand Down Expand Up @@ -220,6 +222,44 @@ export const getSenderAddress = async <
return error.args[0] as Address
}

if (revertError instanceof UnknownRpcError) {
const parsedBody: any = JSON.parse(
(revertError as unknown as any).cause.body
)
const revertData = parsedBody.error.data

const hexStringRegex = /0x[a-fA-F0-9]+/
// biome-ignore lint/suspicious/noExplicitAny:
const match = revertData.match(hexStringRegex)

if (!match) {
throw new Error(
"Failed to parse revert bytes from RPC response"
)
}

const data: Hex = match[0]

const error = decodeErrorResult({
abi: [
{
inputs: [
{
internalType: "address",
name: "sender",
type: "address"
}
],
name: "SenderAddressResult",
type: "error"
}
],
data
})

return error.args[0] as Address
}

throw e
}

Expand Down
Loading