Skip to content

Commit

Permalink
add custom error decoding example
Browse files Browse the repository at this point in the history
  • Loading branch information
Thegaram committed Apr 9, 2024
1 parent bdc54db commit 5925f61
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/src/decode-error.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 5925f61

Please sign in to comment.