sol-utils.ts 468 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { ethers } from 'ethers'

const errorABI = new ethers.utils.Interface([
  {
    type: 'function',
    inputs: [
      {
        type: 'string',
      },
    ],
    name: 'Error',
    stateMutability: 'pure',
  },
])

export const decodeSolidityError = (err: string): string => {
  return errorABI.decodeFunctionData('Error', err)[0]
}

export const encodeSolidityError = (message: string): string => {
  return errorABI.encodeFunctionData('Error', [message])
}