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:
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
--id device-001 \
--type sensor.temperature \
--location "lab-eu-01" \
--pubkey 0x9b31...fd72
List known devices
$ m2ctl device list
Open a secure channel
--from device-001 \
--to device-042 \
--purpose telemetry
Send a message
--channel ch-7f92c1e8 \
--payload '{ "temp_c": 21.3, "status": "ok" }'
SDK Examples
The SDK wraps the same primitives exposed by the protocol: handshake, channels, messaging and settlement.
Initialize client
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
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
{
"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
{
"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
--from device-001 \
--to device-042 \
--amount 12.5 \
--asset M2 \
--ref ch-7f92c1e8
SDK payment
await client.settle({
from: "device-001",
to: "device-042",
amount: 12.5,
asset: "M2",
reference: "ch-7f92c1e8",
});Transaction representation
{
"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.