AbiItem.fromAbi
Extracts an AbiItem.AbiItem
from an Abi.Abi
given a name and optional arguments.
Imports
Named
import { AbiItem } from 'ox'
Examples
ABI Items can be extracted by their name using the name
option:
import { Abi, AbiItem } from 'ox'
const abi = Abi.from([
'function foo()',
'event Transfer(address owner, address to, uint256 tokenId)',
'function bar(string a) returns (uint256 x)',
])
const const item: {
readonly name: "Transfer";
readonly type: "event";
readonly inputs: readonly [...];
}item = AbiItem.fromAbi(abi, 'Transfer')
Extracting by Selector
ABI Items can be extract by their selector when Hex.Hex
is provided to name
.
import { Abi, AbiItem } from 'ox'
const abi = Abi.from([
'function foo()',
'event Transfer(address owner, address to, uint256 tokenId)',
'function bar(string a) returns (uint256 x)',
])
const const item: {
readonly name: "foo";
readonly type: "function";
readonly stateMutability: "nonpayable";
readonly inputs: readonly [];
readonly outputs: readonly [];
} | {
readonly name: "Transfer";
readonly type: "event";
readonly inputs: readonly [...];
} | {
...;
}item = AbiItem.fromAbi(abi, '0x095ea7b3')
Definition
function fromAbi<abi, name, args, allNames>(
abi: abi | Abi.Abi | readonly unknown[],
name: Hex.Hex | (name extends allNames ? name : never),
options?: fromAbi.Options<abi, name, args>,
): fromAbi.ReturnType<abi, name, args>
Source: src/core/AbiItem.ts
Parameters
abi
- Type:
abi | Abi.Abi | readonly unknown[]
The ABI to extract from.
name
- Type:
Hex.Hex | (name extends allNames ? name : never)
The name (or selector) of the ABI item to extract.
options
- Type:
fromAbi.Options<abi, name, args>
- Optional
Extraction options.
options.args
- Type:
allArgs | (Widen & (args extends allArgs ? unknown : never))
- Optional
options.prepare
- Type:
boolean
- Optional
Whether or not to prepare the extracted item (optimization for encoding performance).
When true
, the hash
property is computed and included in the returned value.
Return Type
The ABI item.
fromAbi.ReturnType<abi, name, args>