Constant Module
Module Functionality
The Constant Module is used to define fixed value variables for reference in subsequent workflows. Through this module, users can set a fixed value for a variable and choose its type. The Constant Module is suitable for defining global constants, preset values, or initialization parameters.
Module Features
-
Supports Multiple Data Types:
- Constant values can be set to the following data types:
- String: String type.
- Integer: Integer type.
- Boolean: Boolean type (
true/false
). - Number: Floating-point number type.
- Object: Object type.
- Array: Array type.
- Constant values can be set to the following data types:
-
Fixed Output Format:
- The module’s output data type is determined by the type selected in the
Value
section and directly provided for subsequent references.
- The module’s output data type is determined by the type selected in the
-
Single Constant Limitation:
- Only one constant can be created at a time.
- To define multiple constants, drag multiple Constant Module instances.
-
Module Naming:
- The name editing field at the top of the module is used to name the constant, which serves as the identifier for referencing the constant in subsequent modules.
- It is recommended to use concise and easily recognizable names, such as
api_key
oris_active
.
-
Template Functionality:
- The module supports templated configuration. By enabling the
Template
function, users can reuse the DApp without editing the entire workflow and only need to replace certain constants. - This feature significantly improves development efficiency, making workflow maintenance and upgrades more convenient.
- The module supports templated configuration. By enabling the
Module Tutorial
1. Module Configuration
-
Add Module:
- Drag the Constant Module into the workspace.
-
Set the
Module Name
:- Click the name editing field at the top of the module to set a unique name for the constant.
- The name will serve as the identifier for referencing the constant in subsequent modules.
-
Set the
Value
:- Enter the value of the constant in the
Value
field. - Select the data type of the constant value (e.g.,
String
,Integer
, etc.).
- Enter the value of the constant in the
-
Enable Template Functionality (Optional):
- Turn on the
Template
switch, and fill in theTitle
andDescription
fields to provide an entry point for custom configuration when reusing workflows.
- Turn on the
2. Input Data
This module does not require external input. All values are directly defined by the user in the Value
field.
3. Output Data
- Output Format:
- The module’s output format is determined by the data type selected in the
Value
section. - The output value of the Constant Module can be referenced as a variable in subsequent modules.
- The module’s output format is determined by the data type selected in the
Template Functionality Introduction
-
Purpose of Templates:
- When the
Template
function is enabled, users can adjust workflows by replacing specific constants without modifying the entire logic. - Suitable for developers providing standardized workflow templates with adjustable configurations for users.
- When the
-
Configure Template Parameters:
- Title: Provide a clear title for the template to describe the constant’s function.
- Description: Provide detailed explanations of the constant’s purpose and significance within the template.
- Validate: Support validation of template input values, including the following constraints:
- Subtype: Restrict the subtype of the input value (e.g., array element type).
- Min Length: Define the minimum length for arrays or strings.
- Max Length: Define the maximum length for arrays or strings.
- Code: Allow insertion of custom validation logic.
-
Applicable Scenarios:
- Ideal for developers providing customizable DApp templates.
- Users only need to replace key constants to adjust workflows without redesigning the entire process.
Parameter Constraints and Rules
-
Supported Data Types:
- Users need to select the appropriate data type based on actual needs.
- Supported types include
String
,Integer
,Boolean
,Number
,Object
, andArray
.
-
Constant Value Configuration Rules:
- If the
String
type is selected, a valid string must be entered. - If the
Array
type is selected, it must be in JSON array format (e.g.,[1, 2, 3]
). - If the
Object
type is selected, it must be in JSON object format (e.g.,{"key": "value"}
).
- If the
-
Name Uniqueness:
- Module names must be unique to ensure accurate referencing in subsequent modules.
Notes
-
Single Constant Limitation:
- Each module can only define one constant. To define multiple constants, drag multiple modules.
-
Enabling Template Functionality:
- After enabling the Template function, use the title and description to guide users in quickly completing configurations.
-
Type Matching:
- When referencing the output of the Constant Module, ensure subsequent modules can accept the data type.
-
Validation Rules:
- When enabling the
Validate
function, use rules such as minimum and maximum values, subtypes, etc., to restrict input content.
- When enabling the
Applicable Examples
-
Defining a Global String Variable:
- Configuration:
- Module Name:
api_key
Value
:API_KEY_123
- Type:
String
- Module Name:
- Usage: Used to reference the API key consistently across multiple modules in the workflow.
- Configuration:
-
Defining a Boolean Constant:
- Configuration:
- Module Name:
is_enabled
Value
:true
- Type:
Boolean
- Module Name:
- Usage: Serves as a toggle for logic control.
- Configuration:
-
Defining an Array Variable:
- Configuration:
- Module Name:
user_ids
Value
:[1, 2, 3, 4]
- Type:
Array
- Module Name:
- Usage: Provides initial data for loops or batch processing.
- Configuration:
-
Enabling Template Functionality:
- Configuration:
- Module Name:
template_example
Value
:["example_value_1", "example_value_2"]
- Enable the
Template
function, set the title toUser IDs
, and the description toThis is a list of user IDs used in the workflow.
- Module Name:
- Usage: Allows users to replace
user_ids
when reusing workflows without modifying the entire workflow logic.
- Configuration: