Skip to main content

Try it Live

Run ABI examples in the interactive playground

    Usage Examples

    Find and Use Function

    import * as Abi from 'tevm/Abi'
    
    const abi = [...] // Full contract ABI
    
    const transferFn = Abi.getItem(abi, "transfer", "function")
    
    if (transferFn && transferFn.type === "function") {
      const calldata = Abi.Function.encodeParams(transferFn, [to, amount])
      await provider.call({ to: contractAddress, data: calldata })
    }
    

    Error Handling

    import * as Abi from 'tevm/Abi'
    
    const abi = [...]
    
    const item = Abi.getItem(abi, "nonExistent", "function")
    if (!item) {
      throw new Error("Function not found in ABI")
    }
    

    See Also

    • encode - Encode using ABI item
    • decode - Decode using ABI item