Sui Move Events Listeners and Webhooks - Basic Integrations Examples

Tutorial

For businesses and developers, integrating with chains like Sui offers a unique opportunity to innovate and create transformative solutions. In this series, we delve into our journey of building on Sui, shedding light on the intricacies of integrations, focusing on event listeners and webhooks, which have been integral components of TheMoveDev and SuiQL, Sui indexing GraphQL Event API made by Peeranha.

If you have any questions, you can ask them here.

The code is implemented in TypeScript and runs within the AWS Cloud environment using serverless technologies. Serverless is used for deployments. Serverless Offline is used to run the code locally.

Sui Events Listeners and Webhooks: A Brief Overview

Blockchain networks are inherently decentralized, making real-time data integration a challenging feat. This is where event listeners and webhooks come into play. Event Listeners are mechanisms that constantly monitor blockchain activity, identifying and capturing specific events of interest. Webhooks, on the other hand, are HTTP callbacks triggered by these events, allowing seamless communication between different applications.

The Sui Integration Architecture

Our integration journey with Sui involved a comprehensive architecture comprising several key components.

Events Listener

The Events Listener, a robust ECS Fargate task, plays a pivotal role in our integration setup. It continuously polls new events from the Sui nodes (Sui full node), ensuring that our system stays up-to-date with the latest blockchain activities.

Sui Events Listener Queue

Events identified by the Events Listener are added to the Sui Listener Queue, a FIFO SQS queue. This queue acts as an intermediary storage, enabling efficient event processing and management.

Webhook Invoker

Responsible for invoking webhooks, the Webhook Invoker is a Lambda function that ensures seamless communication between our system and external applications. It acts as a bridge, facilitating the transmission of event data to the designated endpoints.

Event Bridge

The Event Bridge, a pivotal component of our architecture, invokes the Webhook Invoker Lambda whenever new items are added to the Sui Listener Queue. This real-time triggering mechanism ensures prompt webhook invocations.

Webhook

The Webhook, implemented as an AWS Lambda function, processes individual events received from the Sui blockchain. This component plays a crucial role in interpreting the event data and executing specific actions based on the event type.

Workflow: How It All Comes Together

Understanding the workflow is essential to grasp the seamless operation of our integration architecture.

Events Listener Operation

  • The Events Listener operates in a continuous loop, making RPC API calls to suix_queryEvents to retrieve new events associated with a configured package ID.
  • The Events Listener maintains a cursor value in DynamoDB, ensuring it reads events chronologically.

Adding Events to Sui Listener Queue

  • Whenever the Events Listener identifies new events, it adds them to the Sui Listener Queue for further processing.

Event Bridge Trigger

  • The AWS Event Bridge monitors the Sui Listener Queue and triggers the Webhook Invoker Lambda as soon as new items are added. This ensures real-time event processing.

Webhook Invocation

  • The Webhook Invoker, once triggered, invokes the Webhook Lambda function for each event present in the queue.
Running Locally - Dev Playground
  • Serverless offline plugin is used to run the solution locally. Listener runs in ECS task in the cloud. ECS is not available for serverless offline. For that reason, uncomment the sui-events-listener lambda function in serverless.yml. This function will read new events from the blockchain once per minute.
  • Install dependencies:
npm install
  • Install DynamoDb:
npm run dynamodb:install

If you are getting an error Error getting DynamoDb local latest tar.gz location undefined: 403 on this step then it means that there is still a known issue in serverless-dynamodb-local. It is discussed here or you can leave your question on Sui Move Q&A.

  • In node_modules/dynamodb-localhost/dynamodb/config.json URL to https://s3.us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz (add s to http);
  • In node_modules/dynamodb-localhost/dynamodb/installer.j change http to https;
  • To start services run:
npm run dev
Event Listener Deployment to AWS
  1. Install AWS CLI;
  2. Configure AWS CLI;
aws configure
  1. Modify values in stages\test.yml and stages\prod.yml;
  2. Start deployment;
npm run deploy:test

or

npm run deploy:prod

To be continued...

In this first part of our series on Sui integrations, we've explored the foundational concepts of event listeners and webhooks, unraveling the intricate architecture behind our integration with the Sui blockchain. Stay tuned for the upcoming parts, where we'll delve deeper into our journey, sharing insights, challenges, and innovative solutions that have shaped our experience.

Feel free to leave your questions here.

Answers 0