Developer Integration
How to integrate Gao Network (Transport Layer) into your application. The Transport Layer provides messaging, routing, and relay capabilities via @gao/system-sdk
Quick Start#
pnpm add @gao/system-sdk
import { GaoSDK } from '@gao/system-sdk'
const sdk = new GaoSDK({
domain: 'myapp.gao',
apiKey: process.env.GAO_API_KEY,
})
All transport functionality is under sdk.transport.
Send a Message#
await sdk.transport.message.send({
to: 'alice.gao', // recipient's Gao Domain
content: 'Hello!',
type?: 'text', // 'text' | 'notification' | 'agent_action'
encrypted?: true, // default true — always E2EE
})
Messages are:
-
End-to-end encrypted (Signal Protocol) — relay cannot read content
-
Delivered P2P when both parties are online (WebRTC DataChannel)
-
Queued on Gao Relay when recipient is offline (TTL 7 days, deleted on ACK)
Receive Messages#
const unsub = sdk.transport.message.subscribe((msg) => {
console.log(msg.from) // "alice.gao"
console.log(msg.decrypted.content) // decrypted message text
console.log(msg.decrypted.type) // message type
console.log(msg.timestamp) // unix ms
})
// Stop listening
unsub()
Agent Sends as Bot Identity#
// Agent sends with its own identity (not the domain owner's)
await sdk.transport.message.sendAsAgent(
'booking-bot-id', // registered agent ID
'customer-routing-tag', // recipient
'Your booking is confirmed for tomorrow at 3pm.'
)
Routing#
// Select best relay node for a recipient
const route = await sdk.transport.selectRoute({
recipient: 'alice.gao',
priority: 'low_latency', // 'low_latency' | 'high_reliability'
})
// route.node_endpoint, route.latency_ms, route.region
// Validate a relay path
const valid = await sdk.transport.validateRelayPath([
'relay1.meshii.app',
'relay2.meshii.app',
])
Storage Mode#
Messages default to zero storage. Users can opt in:
// Default: no storage (messages lost on app close)
sdk.transport.setStorageMode('none')
// Save on device (encrypted)
sdk.transport.setStorageMode('local')
// Backup to GaoStorage (user pays fee)
sdk.transport.setStorageMode('depin')
React Hook#
import { useMessages } from '@gao/system-sdk/react'
function ChatWindow({ contact }: { contact: string }) {
const { messages, send, loading } = useMessages(sdk, contact)
return (
<div>
{messages.map(msg => (
<div key={msg.id} className={msg.from === sdk.domain ? 'sent' : 'received'}>
{msg.decrypted.content}
</div>
))}
<input
onKeyDown={(e) => {
if (e.key === 'Enter') send(e.currentTarget.value)
}}
/>
</div>
)
}
Standalone Messaging SDK#
For apps that only need messaging (not the full SDK):
pnpm add @gao/meshii-sdk
import { MeshiiClient } from '@gao/meshii-sdk'
const client = new MeshiiClient({
network: 'gao-depin',
apiKey: 'your_api_key',
})
await client.init({ identity: passkeyOrGaoDomain })
await client.send({ to: 'alice.gao', content: 'Hello!' })
client.onMessage((msg) => {
console.log(msg.decrypted.content)
})
Common Integration Patterns#
Booking Confirmation
await sdk.transport.message.send({
to: customerDomain,
content: `Confirmed: ${service} on ${date} at ${time}. Reply to reschedule.`,
type: 'notification',
})
Payment Notification
await sdk.transport.message.send({
to: merchantDomain,
content: JSON.stringify({
type: 'payment_received',
amount: '25.00',
currency: 'USDC',
from: customerDomain,
}),
type: 'agent_action',
})
Support Bot
const unsub = sdk.transport.message.subscribe(async (msg) => {
if (msg.decrypted.type === 'text') {
// Run agent to generate reply
const reply = await runSupportAgent(msg.decrypted.content)
await sdk.transport.message.sendAsAgent('support-bot', msg.from, reply)
}
})
Scheduled Reminder
// Run at 9am daily — sends reminders via Meshii
const job = await sdk.intelligence.scheduler.create({
agent_id: 'reminder-agent',
owner_domain: 'myapp.gao',
trigger_type: 'cron',
trigger_config: { expression: '0 9 * * *', timezone: 'America/Chicago' },
})
// Agent sends via sdk.transport automatically during execution
API Endpoints (Direct)#
For server-to-server integration without the SDK:
POST /transport/messages
Auth: Bearer token
Body: { to: string, content: string, type?: string, encrypted?: boolean }
Response: { message_id: string, delivered: boolean }
WebSocket: wss://relay.meshii.app/collab?token=<jwt>
Events (server → client):
{ type: "message", from: string, content: string, timestamp: number }
{ type: "ack", message_id: string }
{ type: "ping" }
Capability Required#
Transport actions require capability tokens:
| Action | Capability |
|---|---|
| Send message | transport:message:send |
| Send as agent | transport:message:send + agent registered |
| Select route | transport:relay:test |
const cap = await sdk.developer.capability.request('transport:message:send', 'myapp.gao', 3600)
// SDK attaches automatically to sdk.transport calls
Wire Format#
All messages on Gao Network use a binary envelope format. See Meshii Protocol for the full wire format specification including magic bytes, version, routing tag layout, and ciphertext structure.
Testnet#
Test your integration before going to production:
const sdk = new GaoSDK({
domain: 'myapp.gao',
apiKey: process.env.GAO_API_KEY,
environment: 'testnet', // ← use testnet
})
Testnet relay nodes are operated by Toii Labs. Messages on testnet are not routed to production users.
PreviousNode Types & SetupNextWire Format & Protocol Reference