Usage Examples
Matching Error Selectors
See Also
- getSignature - Get error signature string
- encodeParams - Encode error data
- decodeParams - Decode error data
Get 4-byte error selector for custom errors
import { AbiError } from 'tevm'
const insufficientBalance = new AbiError({
type: "error",
name: "InsufficientBalance",
inputs: [
{ type: "uint256", name: "balance" },
{ type: "uint256", name: "required" }
]
})
try {
await contract.call()
} catch (error) {
const errorSelector = error.data.slice(0, 10)
if (errorSelector === insufficientBalance.getSelector()) {
// Decode error parameters
const params = insufficientBalance.decodeParams(error.data)
console.log(`Balance: ${params[0]}, Required: ${params[1]}`)
}
}
Was this page helpful?