Skip to content

toFunctionSignature

Returns the signature for a given function definition.

Install

import { toFunctionSignature } from 'viem'

Usage

import { 
const toFunctionSignature: (def: string | AbiFunction | AbiEvent) => string

Returns the signature for a given function or event definition.

toFunctionSignature
} from 'viem'
// from function definition const
const signature_1: string
signature_1
=
function toFunctionSignature(def: string | AbiFunction | AbiEvent): string

Returns the signature for a given function or event definition.

toFunctionSignature
('function ownerOf(uint256 tokenId)')
Output: ownerOf(uint256)
// from an `AbiFunction` on your contract ABI const
const signature_2: string
signature_2
=
function toFunctionSignature(def: string | AbiFunction | AbiEvent): string

Returns the signature for a given function or event definition.

toFunctionSignature
({
name: string
name
: 'ownerOf',
type: "function"
type
: 'function',
inputs: readonly AbiParameter[]
inputs
: [{
name: string
name
: 'tokenId',
type: "uint256"
type
: 'uint256' }],
outputs: readonly AbiParameter[]
outputs
: [],
stateMutability: AbiStateMutability
stateMutability
: 'view',
})
Output: ownerOf(uint256)

Returns

string

The signature as a string value.

Parameters

definition

  • Type: string | AbiFunction

The function definition to generate a signature for.