Developers

Everything in M2 Protocol is designed to be inspectable, scriptable and automatable. No black boxes. Just clear primitives for building real machine-to-machine workflows.

Getting Started

You can interact with M2 Protocol through:

A command-line tool (m2ctl) for operators and power users
A programmatic SDK for developers
Standard JSON and HTTP/WebSocket interfaces

Below are example flows that illustrate how devices are registered, connected and settled.

CLI Examples

Command-line tool for device registration, channel management and settlement operations.

Device registration

M2 ProtocolM2 CLI
# Register a new device in the registry
$ m2ctl device register \
--id device-001 \
--type sensor.temperature \
--location "lab-eu-01" \
--pubkey 0x9b31...fd72
[INFO] Device identity created
[INFO] Device ID: device-001
[INFO] Registry entry: m2://devices/device-001
[OK] Device successfully registered

List known devices

M2 ProtocolM2 CLI
# List known devices
$ m2ctl device list
ID TYPE LOCATION
device-001 sensor.temperature lab-eu-01
device-042 actuator.cooling rack-a3

Open a secure channel

M2 ProtocolCHANNEL OPEN
# Device A opens a channel with Device B
$ m2ctl channel open \
--from device-001 \
--to device-042 \
--purpose telemetry
[HANDSHAKE] device-001 → device-042
[HANDSHAKE] device-042 → device-001
[CHANNEL] id: ch-7f92c1e8
[CHANNEL] mode: encrypted
[OK] Channel ch-7f92c1e8 is now active

Send a message

M2 ProtocolMESSAGE SEND
# Send a message through the channel
$ m2ctl channel send \
--channel ch-7f92c1e8 \
--payload '{ "temp_c": 21.3, "status": "ok" }'
[TX] ch-7f92c1e8 payload size=42B
[ACK] device-042 confirmed receipt

SDK Examples

The SDK wraps the same primitives exposed by the protocol: handshake, channels, messaging and settlement.

Initialize client

TypeScript Example
import { M2Client } from "@m2/protocol";

const client = new M2Client({
  deviceId: "device-001",
  apiKey: process.env.M2_API_KEY,
  endpoint: "https://api.m2protocol.net",
});

Handshake, channel and messaging

TypeScript Example
async function main() {
  // 1) Perform handshake
  await client.handshake("device-042");

  // 2) Open channel
  const channel = await client.openChannel({
    to: "device-042",
    purpose: "telemetry",
  });

  // 3) Send message
  await channel.send({
    temp_c: 21.3,
    status: "ok",
    ts: new Date().toISOString(),
  });

  console.log("Telemetry sent via", channel.id);
}

main().catch(console.error);

Message Model

M2 Protocol is payload-agnostic. Messages are simple JSON documents that follow a few basic rules: typed, timestamped and traceable.

Telemetry message

Telemetry Payload
{
  "type": "telemetry.temperature",
  "from": "device-001",
  "to": "device-042",
  "payload": {
    "temp_c": 21.3,
    "humidity": 40.1,
    "status": "ok"
  },
  "context": {
    "channel_id": "ch-7f92c1e8",
    "location": "lab-eu-01"
  },
  "ts": "2025-06-12T08:21:05.123Z"
}

Control message

Command Payload
{
  "type": "command.setpoint",
  "from": "device-042",
  "to": "device-001",
  "payload": {
    "target_temp_c": 19.5,
    "mode": "cooling"
  },
  "context": {
    "priority": "high"
  },
  "ts": "2025-06-12T08:21:07.456Z"
}

Settlement

When value needs to be exchanged, devices can trigger settlement operations directly from the channel context.

CLI payment

M2 ProtocolSETTLEMENT
# Device-001 pays Device-042 for processing 1,000 messages
$ m2ctl settlement pay \
--from device-001 \
--to device-042 \
--amount 12.5 \
--asset M2 \
--ref ch-7f92c1e8
[SETTLEMENT] Preparing payment...
[SETTLEMENT] Route: device-001 → m2-node-eu → device-042
[SETTLEMENT] Tx: 0x8ad4...b91c
[OK] 12.5 M2 transferred to device-042

SDK payment

TypeScript Example
await client.settle({
  from: "device-001",
  to: "device-042",
  amount: 12.5,
  asset: "M2",
  reference: "ch-7f92c1e8",
});

Transaction representation

Transaction JSON
{
  "tx_id": "0x8ad4...b91c",
  "from": "device-001",
  "to": "device-042",
  "amount": 12.5,
  "asset": "M2",
  "channel": "ch-7f92c1e8",
  "status": "confirmed",
  "ts": "2025-06-12T08:21:10.001Z"
}

Observability

Every interaction across M2 Protocol can be traced end-to-end: from registry lookups to channel messages and settlements.

Complete trace example

M2 ProtocolTRACE VIEWER
TRACE: m2-flow-10483
[1] device-001 → REGISTRY action=lookup target=device-042
[2] device-001 ↔ device-042 action=handshake result=accepted
[3] channel ch-7f92c1e8 action=open mode=encrypted
[4] channel ch-7f92c1e8 action=message type=telemetry size=42B
[5] settlement engine action=payment amount=12.5 M2 status=confirmed

Security events

Security Event Log
[SECURITY] 2025-06-12T08:21:09Z HANDSHAKE_REJECTED device-999 reason=unregistered
[SECURITY] 2025-06-12T08:21:10Z ALERT_RAISED severity=low scope=edge-test-lab