Skip to main content

Try it Live

Run ABI examples in the interactive playground

    Usage Examples

    Format Function

    import * as Abi from 'tevm/Abi'
    
    const fn = {
      type: "function",
      name: "balanceOf",
      inputs: [{ type: "address", name: "owner" }],
      outputs: [{ type: "uint256", name: "balance" }]
    }
    
    console.log(Abi.format(fn))
    // "function balanceOf(address owner) returns (uint256 balance)"
    

    Format Event

    import * as Abi from 'tevm/Abi'
    
    const event = {
      type: "event",
      name: "Transfer",
      inputs: [
        { type: "address", name: "from", indexed: true },
        { type: "address", name: "to", indexed: true },
        { type: "uint256", name: "value" }
      ]
    }
    
    console.log(Abi.format(event))
    // "event Transfer(address indexed from, address indexed to, uint256 value)"
    

    Format Error

    import * as Abi from 'tevm/Abi'
    
    const error = {
      type: "error",
      name: "InsufficientBalance",
      inputs: [
        { type: "uint256", name: "balance" },
        { type: "uint256", name: "required" }
      ]
    }
    
    console.log(Abi.format(error))
    // "error InsufficientBalance(uint256 balance, uint256 required)"
    

    See Also