AbiError.encode
ABI-encodes the provided error input (inputs
), prefixed with the 4 byte error selector.
Imports
Named
import { AbiError } from 'ox'
Examples
import { AbiError } from 'ox'
const error = AbiError.from(
'error InvalidSignature(uint r, uint s, uint8 yParity)'
)
const data = AbiError.encode(
error,
[1n, 2n, 0]
)
'0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
You can extract an ABI Error from a JSON ABI with AbiError.fromAbi
:
import { Abi, AbiError } from 'ox'
const abi = Abi.from([
// ...
{
name: 'InvalidSignature',
type: 'error',
inputs: [
{ name: 'r', type: 'uint256' },
{ name: 's', type: 'uint256' },
{ name: 'yParity', type: 'uint8' },
],
},
// ...
])
const error = AbiError.fromAbi(abi, 'InvalidSignature')
const data = AbiError.encode(
error,
['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
)
'0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
Definition
function encode<abiError>(
abiError: abiError,
args: encode.Args<abiError>,
): encode.ReturnType
Source: src/AbiError.ts
Parameters
abiError
- Type:
abiError
ABI Error to encode
args
- Type:
encode.Args<abiError>
Error arguments
Return Type
ABI-encoded error name and arguments
encode.ReturnType