How Kwala functions work
Kwala functions follow these steps that create a fully event-driven automation pipeline:Define and deploy logic
Create your Kwala function with custom business logic and deploy it to the network.
Receive input data
The function receives structured JSON input from blockchain events or other sources.
Defining a Kwala function
To bring your custom logic on-chain, you define a Kwala function within a workflow configuration. The function is deployed using adeploy action. The following example deploys a Kwala function that will be activated immediately after deployment:
- Name: A unique identifier for this workflow (
deploycontract-kalp-qa-02) - ExecuteAfter: Set to
immediate, meaning the deployment runs as soon as the workflow is submitted - Actions: Contains the deployment action with the following properties:
- Name: Identifies this specific action (
DeployContract) - Type: Set to
deployto indicate a contract deployment - ChainID: The target blockchain network (
1905for Kalp Chain) - EncodedGoContract: Your Go contract logic, Base64-encoded
- RetriesUntilSuccess: Number of retry attempts if deployment fails (
5)
- Name: Identifies this specific action (
EncodedGoContract field. The Kwala function logic is written in Go and packaged into your workflow. This logic executes on-chain and handles three core responsibilities - parsing input data, applying conditional logic, and emitting events.
ERC20Transfer for input and EventData for output), then implements ComputeEngine to parse incoming transfer data, check if the amount exceeds 100,000 tokens, and emit a categorized event for high-value transfers.
Anatomy of a Kwala function
The entry point Every Kwala function usesComputeEngine as its entry point:
payload parameter contains JSON-encoded structured data that your function processes.
Custom input structures
You can define custom data structures to parse the incoming JSON payload. Your structure can include any fields, as long as the incoming JSON matches the schema you define
If address tracking is used, the input is provided as a string containing the transaction receipt. Otherwise, you can define your own custom structures.
TriggerEventName: PaymentStatus(transaction_id string, amount number, status string) and access values using positional references:
re.event(0)→transaction_idre.event(1)→amountre.event(2)→status
Applying conditions and rules
Your Kwala function can apply any deterministic logic to evaluate and classify input data. The following example evaluates the amount of tokens transferred and classifies the transaction based on a threshold:Emit blockchain events
Once your function processes the input and applies its logic, you can use theEmitEvent function to emit events.
Listen to Kwala function events
Other workflows can listen to events emitted by your Kwala function using a trigger configuration. The following example configures a trigger that activates every time theTokenTransferEvaluated event occurs:
- TriggerEventName: Event signature with parameter names and types
- RepeatEvery: When to repeat (
eventfor every occurrence) - ExecuteAfter: When to execute after the event
Use event data in actions
You can use there.event() function to reference event fields positionally in your workflow actions.
For the TokenTransferEvaluated(from, to, amount, category) event:
re.event(0)→fromaddressre.event(1)→toaddressre.event(2)→amountre.event(3)→category
What Kwala functions enable
Once deployed, the entire Kwala function pipeline runs automatically without manual intervention. With Kwala functions, you can build:- On-chain decision logic that applies custom business rules to blockchain data
- Event-driven automation that triggers workflows from computed events
- Data enrichment pipelines that transform raw data into actionable information
- Connected workflows that chain together through emitted events
- Blockchain-to-external integrations that bridge on-chain activity with external systems
Complete end-to-end workflow configuration
This section presents a complete end-to-end configuration using three workflows. Together, these workflows demonstrate how a Kwala function is deployed, executed, and how its emitted events trigger external actions. Workflow 1: Kwala function deployment This workflow deploys the Kwala function logic onto the Kalp Chain. The Go contract maps recipient addresses to human-readable names and emitsTransfer events.
Go contract logic (decoded):
ComputeEngine function with the event data.
YAML 2: Address tracking workflow
Transfer event emitted by the Kwala function and executes an external action (Telegram notification) using the enriched event data.
YAML 3: Event listener workflow
Deploy the Kwala function
Workflow 1 deploys the Go contract containing your business logic to Kalp Chain.
Detect blockchain activity
Workflow 2 monitors the source contract (on Polygon Amoy) for address tracking events.
Invoke ComputeEngine
When activity is detected, Workflow 2 calls the deployed Kwala function with the transaction data.
Emit enriched event
The Kwala function processes the data, maps the recipient address to a name, and emits a
Transfer event.