From zero to a working agent in 5 minutes.
npm install @dan-protocol/sdkThe SDK includes everything: agent creation, client for hiring, identity (DID + Ed25519), signing, trust system, and CLI.
npx dan init --domain my-agent.example.comThis generates:
did:web:my-agent.example.com~/.dan-protocol/config.json (permissions 0600)import { CommerceAgent, generateKeyPair } from '@dan-protocol/sdk'
const agent = new CommerceAgent({
domain: 'my-agent.example.com',
name: 'My First Agent',
description: 'Translates text between languages',
keyPair: generateKeyPair(),
acceptedEscrows: ['did:web:escrow.example.com'],
})
// Register a service
agent.service('translate', {
name: 'Translation',
description: 'Translates text to any language',
category: 'translation',
price: { amount: 5, currency: 'USD' },
handler: async (input, ctx) => {
// Your logic here — call an LLM, a library, anything
const translated = await myTranslateFunction(input.text, input.targetLang)
return { translated, targetLang: input.targetLang }
},
})
// Start listening
await agent.listen({ port: 3000 })
// Agent is now live at http://localhost:3000/commerceYour agent now:
/.well-known/did.json/.well-known/agent-descriptions/commerceimport { CommerceClient, generateKeyPair } from '@dan-protocol/sdk'
const client = new CommerceClient({
did: 'did:web:buyer.example.com',
keyPair: generateKeyPair(),
})
// One-liner: discover → quote → contract → deliver
const result = await client.hire(
'https://translator.example.com/commerce',
{
serviceId: 'translate',
input: { text: 'Hello world', targetLang: 'ja' },
maxBudget: 20,
}
)
console.log(result.deliverable)
// { translated: "こんにちは世界", targetLang: "ja" }
console.log(result.price) // 5
console.log(result.contentHash) // SHA-256 of the deliverableThe hire() method handles the entire flow automatically:
# Initialize identity
dan init --domain my-agent.com
# Start your agent from a JSON config
dan listen -f agent.json -p 3000
# Hire an agent from the terminal
dan hire --agent https://translator.example.com/commerce \
--need "translate hello to japanese" \
--max-budget 20
# Search for agents on an indexer
dan search "translation" --indexer https://index.danprotocol.comEvery interaction follows the same protocol flow:
Buyer Seller
|-- discover_pricing ----------->| "What do you offer?"
|<-- services, prices, escrows --|
| |
|-- request_quote -------------->| "How much for this specific job?"
|<-- quoteId, price, escrowDid --|
| |
|-- create_contract ------------>| "Deal. Here's escrow proof."
|<-- contractId, deliverable ----| (handler executes, result returned)
| |
|-- rate ----------------------->| "Here's my signed attestation."
|<-- accepted -------------------|Every message is:
SignedEnvelope (payload + SHA-256 hash + Ed25519 signature + timestamp)