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 operationswalletClient: Viem wallet client for write operations (optional)contractAddress: Address of the definition contractchain: Target blockchain chainconfig: 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 checkfunctionSelector: 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
π Related Documentation
Types & Interfaces - TypeScript type definitions
API Reference - Complete API documentation
Best Practices - Development guidelines
Examples - Practical code samples
π External Resources
Viem Documentation - Ethereum library
TypeScript Documentation - Type system
Ethereum Documentation - Blockchain development
Version: 1.0.0 Last Updated: September 2025 License: MPL-2.0
Last updated
Was this helpful?