getAbiItem
Retrieves an item from the ABI.
Import
ts
import { getAbiItem } from 'viem'
Usage
ts
import { getAbiItem } from 'viem'
const encodedData = getAbiItem({
abi: [
{
name: 'x',
type: 'function',
inputs: [{ type: 'uint256' }],
outputs: [],
stateMutability: 'payable'
},
{
name: 'y',
type: 'event',
inputs: [{ type: 'address' }],
outputs: [{ type: 'uint256' }]
stateMutability: 'view'
},
{
name: 'z',
type: 'function',
inputs: [{ type: 'string' }],
outputs: [{ type: 'uint256' }]
stateMutability: 'view'
}
],
name: 'x'
)
/**
* {
* name: 'y',
* type: 'event',
* inputs: [{ type: 'address' }],
* outputs: [{ type: 'uint256' }]
* stateMutability: 'view'
* }
*/
Returns
AbiItem
The ABI item.
Parameters
abi
- Type:
Abi
The contract's ABI.
ts
const encodedData = getAbiItem({
abi: [...],
name: 'x'
)
name
- Type:
string
Name of the ABI item to extract.
ts
const encodedData = getAbiItem({
abi: [...],
name: 'x'
)
args (optional)
- Type: Inferred.
Optional arguments to identify function overrides.
ts
const encodedData = getAbiItem({
abi: [...],
name: 'y',
args: ['0x0000000000000000000000000000000000000000']
)