Skip to main content
Onboarding users into a Web3 app often means writing data on-chain and then doing off-chain follow ups: welcome messages, analytics, or admin workflows. The usual approach, run a server that polls the chain, stores results, and sends notifications, adds operational overhead and maintenance. This guide shows a lightweight, production-minded pattern:
  • A frontend that writes registration data to a smart contract
  • A small optional backend helper to read records when needed
  • A Kwala workflow that listens for the on-chain RecordSaved event and sends instant Telegram confirmations
Result: secure on-chain registration and immediate off-chain UX, without running a dedicated cron or relay server for the event to notification glue. Kwala provides YAML-driven workflow automation to connect on-chain triggers with off-chain actions (webhooks, bots, contract calls), so you can focus on product logic, not infra.

Objective

Create an onboarding flow where:
  • TRIGGER: Kwala listens for RecordSaved(address,string,string,string,uint256) emitted by the SaveData smart contract when a user registers via the frontend.
  • ACTION: Kwala posts a personalized Telegram welcome message to the registered chat ID.
This provides a real-time, auditable onboarding experience: the data is stored on-chain and users receive immediate confirmation through Telegram, all driven by a YAML workflow.

Prerequisites

Before you begin, ensure you have:
  1. MetaMask (or compatible wallet) connected to the target RPC. This guide uses the Polygon Amoy testnet.
  2. Telegram bot token and chat IDs (create via @BotFather)
  3. Kwala Dashboard access to create and deploy workflows: https://kwala.network/dashboard
  4. Familiarity with Solidity and frontend tooling such as ethers.js, BrowserProvider, simple HTML/JS, or React

Step 1: Smart contract (SaveData.sol)

Deploy the contract below using Remix or your preferred flow. Kwala uses the event ABI to listen for RecordSaved.
Contract address (example): 0x3e2f859DA20e1e74A5696Bf3246606218c246C9F
SaveData.sol
Save the deployed contract address and ABI — Kwala uses the event ABI to detect RecordSaved.

Step 2: Frontend (simple onboarding UI)

A lightweight HTML and ethers frontend collects name + Telegram chat ID and calls saveRecord(...). Open this page in a browser with MetaMask installed.
index.html
Frontend usage:
  1. Open the page in a browser with MetaMask
  2. Click Connect MetaMask and sign the request
  3. Fill Name and Telegram Chat ID (wallet optional)
  4. Click Sign Up — MetaMask will prompt and the frontend calls saveRecord()
  5. Once mined, RecordSaved is emitted

Telegram helper bot (get chat ID)

You can provide a tgBotBtn that opens a bot which replies with the chat ID. Here’s an example bot (Node.js) that replies with the user’s chat ID when they click the /start deep link. Useful for users to capture their chat ID from the browser.
telegram-bot.js
Keep bot tokens secret in production — use environment variables and secure hosting.

Optional step 3: Small backend helper

This optional Node/Express helper demonstrates reading stored records on-chain and sending Telegram messages in bulk. Kwala already handles immediate notifications via events, but you may want a backend for bulk messaging, admin flows, or periodic summaries.
index.js
Use environment variables for tokens and RPC endpoints in production.

Step 4: Kwala workflow (event → Telegram)

Create a Kwala workflow that listens for RecordSaved and posts a Telegram message. This is the core serverless glue — Kwala runs it for you.

Kwala dashboard steps

  1. Open: https://kwala.network/dashboardCreate New Workflow
  2. Name: New_User_Onboardingworkflow (or any name you prefer)
  3. Trigger:
    • Execute After: immediate
    • Repeat Every: event
    • Recurring Source Contract: 0x3e2f859DA20e1e74A5696Bf3246606218c246C9F
    • Recurring Chain ID: 80002 (Polygon Amoy)
    • Recurring Event Name: RecordSaved(address,string,string,string,uint256)
    • Recurring Source Contract ABI: paste the event ABI (Kwala can fetch/accept the ABI)
    • Action Status Notification POST URL:
  4. Action:
    • Action Name: Telegram_notificatier
    • Type: POST API CALL
    • API Endpoint: https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage
    • API Payload:
    • Retries Until Success: 5
    • Execution Mode: parallel (or sequential — choose based on your need)
  5. Save and deploy. Kwala will return the workflow address and status.

YAML configuration

workflow.yaml

Deploy and test

  1. Deploy SaveData or use the provided address: 0x3e2f859DA20e1e74A5696Bf3246606218c246C9F
  2. Serve the frontend and connect MetaMask. Fill name and Telegram chat ID and select Sign Up
  3. Once saveRecord is mined, the contract emits RecordSaved
  4. Kwala detects the event and posts to the configured Telegram chat ID
  5. Optionally use the backend /sendMessages endpoint to read stored records and send messages in bulk

Monitor and debug

Kwala Dashboard Logs

View events processed, API calls, payloads, and retry counts in the Kwala Dashboard → Workflow Logs

Contract Explorer

Verify RecordSaved events and transaction receipts on Amoy Polygonscan
Debug checklist:
  • Validate your bot token and chat ID via Postman/ReqBin before wiring into Kwala
  • Check bot token validity and chat ID correctness if messages don’t arrive
  • Review Kwala logs for HTTP errors and retry traces

Conclusion

You now have a full onboarding pattern that is:
  • Secure and auditable: Records are stored on-chain
  • Real-time and user-friendly: Kwala sends instant Telegram confirmations after the RecordSaved event
  • Low-operational overhead: No polling servers required for event to notification glue
This pattern is extendable in that you can swap Telegram for Discord, email, or custom webhooks; or add a backend for analytics or bulk messaging. Kwala lets you plug in actions quickly without rebuilding infrastructure.

Next Steps

Monitor Your Workflow

Track execution history, debug issues, and optimize your automation

Best Practices

Learn optimization strategies and production patterns