From 5925f614dd39bc250c3a774b9bb5bc07c188cf1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Tue, 9 Apr 2024 10:31:12 +0800 Subject: [PATCH] add custom error decoding example --- examples/src/decode-error.js | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/src/decode-error.js diff --git a/examples/src/decode-error.js b/examples/src/decode-error.js new file mode 100644 index 0000000..2763afa --- /dev/null +++ b/examples/src/decode-error.js @@ -0,0 +1,46 @@ +import { ethers } from 'ethers'; + +import 'dotenv/config'; + +const abi = [ + 'error Unauthorized()', + + 'error BadgeNotAllowed(address badge)', + 'error BadgeNotFound(address badge)', + 'error ExpirationDisabled()', + 'error MissingPayload()', + 'error ResolverPaymentsDisabled()', + 'error RevocationDisabled()', + 'error SingletonBadge()', + 'error UnknownSchema()', + + 'error AttestationBadgeMismatch(bytes32 uid)', + 'error AttestationExpired(bytes32 uid)', + 'error AttestationNotFound(bytes32 uid)', + 'error AttestationOwnerMismatch(bytes32 uid)', + 'error AttestationRevoked(bytes32 uid)', + 'error AttestationSchemaMismatch(bytes32 uid)', + + 'error BadgeCountReached()', + 'error LengthMismatch()', + 'error TokenNotOwnedByUser(address token, uint256 tokenId)', + + 'error CallerIsNotUserProfile()', + 'error DuplicatedUsername()', + 'error ExpiredSignature()', + 'error ImplementationNotContract()', + 'error InvalidReferrer()', + 'error InvalidSignature()', + 'error InvalidUsername()', + 'error MsgValueMismatchWithMintFee()', + 'error ProfileAlreadyMinted()', +]; + +async function main() { + const errData = '0x8baa579f'; + const contract = new ethers.Interface(abi); + const decodedError = contract.parseError(errData); + console.log('error:', decodedError.name); +} + +main();