UNPKG

@jhubbardsf/ethers-decode-error

Version:

Decode ethers.js smart contract errors into human-readable messages

1 lines 1.38 kB
{"version":3,"file":"panic.mjs","sources":["../src/panic.ts"],"sourcesContent":["import { BigNumber } from 'ethers'\n\n// From Hardhat's panic codes\nexport const panicErrorCodeToReason = (errorCode: BigNumber): string | undefined => {\n switch (errorCode.toNumber()) {\n case 0x1:\n return 'Assertion error'\n case 0x11:\n return 'Arithmetic operation underflowed or overflowed outside of an unchecked block'\n case 0x12:\n return 'Division or modulo division by zero'\n case 0x21:\n return 'Tried to convert a value into an enum, but the value was too big or negative'\n case 0x22:\n return 'Incorrectly encoded storage byte array'\n case 0x31:\n return '.pop() was called on an empty array'\n case 0x32:\n return 'Array accessed at an out-of-bounds or negative index'\n case 0x41:\n return 'Too much memory was allocated, or an array was created that is too large'\n case 0x51:\n return 'Called a zero-initialized variable of internal function type'\n default:\n return undefined\n }\n}\n"],"names":["panicErrorCodeToReason","errorCode","toNumber"],"mappings":"AAGa,IAAAA,EAAyB,SAACC,GACrC,OAAQA,EAAUC,YAChB,KAAK,EACH,MAAO,kBACT,QACE,MAAO,+EACT,KAAS,GACP,MAAO,sCACT,KAAK,GACH,MAAO,+EACT,KAAS,GACP,MAAO,yCACT,KAAK,GACH,MAAO,sCACT,QACE,MAAO,uDACT,KAAS,GACP,MAAO,2EACT,KAAK,GACH,MAAO,+DACT,QACE,OAEN"}