-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e8a119
commit a625920
Showing
9 changed files
with
100 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { decodeErrorResult, type Hex } from "viem"; | ||
import { resolveContractAbi } from "../contract/actions/resolve-abi.js"; | ||
import type { ThirdwebContract } from "../index.js"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export async function extractError(args: { | ||
error: unknown; | ||
contract?: ThirdwebContract; | ||
}) { | ||
const { error, contract } = args; | ||
if (typeof error === "object") { | ||
// try to parse RPC error | ||
const errorObj = error as { | ||
message?: string; | ||
code?: number; | ||
data?: Hex; | ||
}; | ||
if (errorObj.data) { | ||
const parsedError = decodeErrorResult({ | ||
data: errorObj.data, | ||
abi: contract ? await resolveContractAbi(contract) : undefined, | ||
}); | ||
return new Error( | ||
`Execution reverted: ${parsedError.errorName} - ${parsedError.args.join( | ||
",", | ||
)}`, | ||
); | ||
} | ||
} | ||
return error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,7 @@ export function prepareContractCall< | |
}, | ||
{ | ||
abi: resolveAbiFunction_, | ||
contract: contract, | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters