All Products
Search
Document Center

Blockchain as a Service:Push MNS Message to Blockchain

Last Updated:Mar 31, 2026

When business events in Alibaba Cloud Simple Message Queue (MNS) need an immutable audit trail, you can use Function Compute to bridge MNS and your blockchain automatically. When a message arrives in an MNS topic, a Function Compute trigger invokes a function that calls your smart contract's REST API and writes the message to the blockchain channel.

How it works

The data pipeline runs in the following sequence:

  1. A message is published to an MNS topic.

  2. The MNS trigger fires the Function Compute function.

  3. The function calls the Blockchain as a Service REST API.

  4. The smart contract writes the message to the blockchain channel.

Prerequisites

Before you begin, ensure that you have:

Push MNS messages to blockchain

Step 1: Configure the function

  1. Go to the mns2blockchain directory in the sample code.

  2. Open index.js and update the following configuration items based on the inline comments:

    Configuration itemDescription
    REST API service addressThe REST API endpoint of your Blockchain as a Service instance
    Refresh tokenThe refresh token for authenticating with the REST API
    Channel nameThe blockchain channel to write messages to
    Smart contract nameThe name of the smart contract to invoke
  3. In index.js, update the smart contract method name and parameters to match your service scenario, using the inline comments as a guide.

  4. Open template.yml and update the Function Compute service name and function name. The defaults are:

    • Service name: octopus

    • Function name: MNS2BlockChain

    For all available configuration options, see the funcraft documentation.

Step 2: Deploy the function

In the mns2blockchain directory, run the following command to deploy the function to Function Compute:

fun deploy

Step 3: Create an MNS topic

In Alibaba Cloud Simple Message Queue (formerly MNS), create a topic. For setup instructions, see Simple Message Queue (formerly MNS) quick start.

Step 4: Configure the MNS trigger

  1. Log on to the Function Compute console.

  2. Navigate to the function deployed in Step 2.

  3. Add an MNS trigger for the function, and set Event Format to JSON.

    Trigger configurations

Important

Set Event Format to JSON. Without this setting, the function cannot parse the message payload correctly.

Step 5: Verify the integration

In the Alibaba Cloud Simple Message Queue (formerly MNS) console, send a test message to the MNS topic. The trigger invokes the function, which calls the smart contract and writes the message to the blockchain channel.