For the complete documentation index, see llms.txt. This page is also available as Markdown.

Definition contract

The Definitions class provides dynamic interaction with any definition library that implements the IDefinition interface. This enables flexible, runtime discovery of contract configurations, operation types, function schemas, role permissions, and workflow definitions.

πŸ“‹ Table of Contents

🎯 Overview

The Definitions class is designed to interact with definition libraries that implement the IDefinition Solidity interface. These libraries provide:

  • Operation Type Definitions: What operations are supported

  • Function Schema Definitions: How functions are structured

  • Role Permission Definitions: Who can do what

  • Workflow Definitions: How operations are executed

Key Benefits

  • Dynamic Discovery: Runtime discovery of contract capabilities

  • Type Safety: Full TypeScript support with comprehensive type definitions

  • Flexible Integration: Works with any compatible definition library

  • Workflow Management: Query and analyze operation workflows

  • Permission Checking: Dynamic role-based permission validation

πŸ—οΈ Architecture

Core Components

Interface Compliance

The class implements the IDefinition TypeScript interface, which mirrors the Solidity IDefinition interface:

πŸš€ Installation & Setup

Prerequisites

Basic Setup

Configuration Options

πŸ“– Basic Usage

Getting Operation Types

Getting Function Schemas

Getting Role Permissions

Getting Workflows

πŸ“š API Reference

Constructor

Parameters:

  • client: Viem public client for read operations

  • walletClient: Viem wallet client for write operations (optional)

  • contractAddress: Address of the definition contract

  • chain: Target blockchain chain

  • config: Optional configuration object

Core Methods

getOperationTypes()

Returns all operation type definitions from the contract.

Returns: Array of operation type objects with operationType (Hex) and name (string).

Example:

getFunctionSchemas()

Returns all function schema definitions from the contract.

Returns: Array of function schema objects.

Example:

getRolePermissions()

Returns all role hashes and their corresponding function permissions.

Returns: RolePermission object with roleHashes and functionPermissions arrays.

Example:

getOperationWorkflows()

Returns all operation workflow definitions.

Returns: Array of operation workflow objects.

Example:

getWorkflowForOperation()

Returns workflow information for a specific operation type.

Parameters:

  • operationType: The operation type hash to get workflow for

Returns: OperationWorkflow object for the specified operation.

Example:

getWorkflowPaths()

Returns all available workflow paths.

Returns: Array of workflow path objects.

Example:

Utility Methods

getOperationTypeByName()

Finds an operation type by its name.

Parameters:

  • operationName: The name of the operation to find

Returns: The operation type hash if found, undefined otherwise.

Example:

getFunctionSchemaBySelector()

Gets function schema by its selector.

Parameters:

  • functionSelector: The function selector to find

Returns: The function schema if found, undefined otherwise.

Example:

hasRolePermission()

Checks if a role has permission for a function.

Parameters:

  • roleHash: The role hash to check

  • functionSelector: The function selector to check permission for

Returns: True if the role has permission, false otherwise.

Example:

getRolesForFunction()

Gets all roles that can execute a specific function.

Parameters:

  • functionSelector: The function selector to check

Returns: Array of role hashes that can execute the function.

Example:

Configuration Methods

getConfig()

Gets the current contract configuration.

Returns: Current configuration object.

Example:

updateConfig()

Updates the contract configuration.

Parameters:

  • config: Partial configuration object to update

Example:

πŸ”§ Advanced Features

Workflow Analysis

Permission Matrix

Dynamic Function Discovery

⚠️ Error Handling

Common Error Types

Error Recovery

Validation

🎯 Best Practices

1. Error Handling

2. Caching

3. Type Safety

4. Configuration Management

5. Performance Optimization

πŸ’‘ Examples

Complete Workflow Analysis

Permission Audit

Dynamic UI Generation

πŸ” Troubleshooting

Common Issues

1. Contract Not Found

2. Network Mismatch

3. RPC Rate Limiting

Debug Mode

Performance Monitoring


πŸ”— External Resources


Version: 1.0.0 Last Updated: September 2025 License: MPL-2.0

Last updated

Was this helpful?