AbiFunction.decodeData
ABI-decodes function arguments according to the ABI Item's input types (inputs
).
Imports
Named
import { AbiFunction } from 'ox'
Examples
import { AbiFunction } from 'ox'
const approve = AbiFunction.from('function approve(address, uint256)')
const data = AbiFunction.encodeData(
approve,
['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
)
// '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
const input = AbiFunction.decodeData(approve, data)
['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
ABI-shorthand
You can also specify an entire ABI object and a function name as parameters to AbiFunction.decodeData
:
import { Abi, AbiFunction } from 'ox'
const abi = Abi.from([...])
const data = '0x...
const input = AbiFunction.decodeData(
abi,
'approve',
data
)
['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
Definition
function decodeData<abi, name, args, abiFunction, allNames>(
abi: abi | Abi.Abi | readonly unknown[],
name: Hex.Hex | (name extends allNames ? name : never),
data: Hex.Hex,
): decodeData.ReturnType
Source: src/core/AbiFunction.ts
Parameters
abi
- Type:
abi | Abi.Abi | readonly unknown[]
name
- Type:
Hex.Hex | (name extends allNames ? name : never)
data
- Type:
Hex.Hex
The data to decode.
Return Type
decodeData.ReturnType<abiFunction>