All Products
Search
Document Center

Blockchain as a Service:Blockchain Event Triggering External Operation

Last Updated:Jul 21, 2023

Prerequisites

  1. The cloud service integration module is installed in the blockchain instance, and Alibaba Cloud Blockchain as a Service (BaaS) is allowed to integrate with Function Compute.

  2. Cloud service integration sample code is downloaded.

  3. Node.js v8.17.0 or later is installed.

  4. Function Compute tool funcraft is installed. For more information, see funcraft introduction and installation method.

Trigger DingTalk notifications for on-chain events

This topic describes how to use the cloud service integration module of Alibaba Cloud BaaS to push events on a blockchain to DingTalk. When an event occurs on the blockchain, you receive a notification on your DingTalk.

Event flow: Blockchain node -> Cloud service integration -> Function Compute -> DingTalk

  1. Create a DingTalk group and add a custom chatbot.

    1. In the DingTalk group, choose Group Settings > Group Assistant > Add more > Custom.

    2. In this example, set Security Settings to Additional Signature. You can set Security Settings as needed. For more information, see DingTalk chatbot

  2. Go to the event2dingtalk/fc directory.

    1. Modify configuration parameters in index.js based on comments. Fill in the DingTalk webhook address and signature key.

    2. Modify the Function Compute service name and function name in template.yml. The default service name is octopus and the default function name is Event2Dingtalk. For more configuration methods, see funcraft documentation.

  3. Execute fun deploy to deploy a function to Function Compute.

  4. In the Alibaba Cloud BaaS console, create a Function Compute trigger for cloud service integration. For more information, see Configure a Function Compute trigger.

    1. Set the trigger event type to Contract.

    2. Fill in the information about the Function Compute instance based on the help documentation. For more information, see Configure a Function Compute trigger.

  5. Initiate a sample transaction on the channel by referring to Initiate sample transactions.

  6. After the approval flow is created and completed, the DingTalk chatbot sends messages in the group.

Trigger SMS notifications for on-chain events

  1. Go to the blockchain2sms/fc directory.

    1. Modify parameters in index.js based on comments. Fill in the AccessKey and AccessKey secret that have the permissions to call Short Message Service (SMS).

    2. Modify SignName, TemplateCode, and TemplateParam based on the SMS configuration.

    3. Modify the Function Compute service name and function name in template.yml. The default service name is octopus and the default function name is BlockChain2SMS. For more configuration methods, see funcraft documentation.

  2. Execute fun deploy to deploy a function to Function Compute.

  3. In the Alibaba Cloud BaaS console, create a Function Compute trigger for cloud service integration.

    1. Set the trigger event type to Contract.

    2. Fill in the information about the Function Compute instance based on the help documentation. For more information, see Configure a Function Compute trigger.

  4. Initiate a sample transaction on the channel by referring to Initiate sample transactions.

  5. If the approval flow meets conditions and is complete, you can receive SMS notifications. You can also view the records of sending messages in the SMS console.

Initiate sample transactions

  1. Deploy sample chaincode taskmgr to the channel by referring to Chaincode Deployment.

  2. Go to the blockchain2sms directory, modify the parameters in main.js based on comments, and fill in the REST API address, refresh token, channel name, and smart contract name. For more information, see Use REST APIs.

  3. Execute npm install to install dependent packages and node main.js to initiate a sample transaction.

Sample successful output

Data pushed to blockchain with transaction 701c7006f26aed8457273a00bbfcc8cea4d75eac958996e07837036ea7e2fdac
{ id: '701c7006f26aed8457273a00bbfcc8cea4d75eac958996e07837036ea7e2fdac',
  status: '200',
  events:
   [ { type: 'Contract',
       platform: 'Fabric',
       instance_id: 'csi-e2ehmfqasth-bcw7tzao2dzeo',
       network: '',
       id: '',
       name: 'event-create-task',
       content: 'eyJuY...TAz' }
Data pushed to blockchain with transaction 60a06a189415db587b49cbf91b46467bce1ea16490b19f6dfc8d520aa31240bc
{ id: '60a06a189415db587b49cbf91b46467bce1ea16490b19f6dfc8d520aa31240bc',
  status: '200',
  events:
   [ { type: 'Contract',
       platform: 'Fabric',
       instance_id: 'csi-e2ehmfqasth-bcw7tzao2dzeo',
       network: '',
       id: '',
       name: 'event-task-finished',
       content: 'eyJuY...p7In0=' } ],
  data: 'eyJu...In0=' }
Data pushed to blockchain with transaction 7810e0496a1c91a16102736b00a6f26da0baa42874a907fff26bff1b7eb3bf27
{ id: '7810e0496a1c91a16102736b00a6f26da0baa42874a907fff26bff1b7eb3bf27',
  status: '200',
  events: [],
  data: 'eyJu...nIn0=' }