A charter needs a principal wallet holding the USDC for the first deposit and a little SOL for the transaction and the rent of two accounts, and the agent key, which signs its consent to the charter. Make the key first if the agent has none:
npx civitas keygen --out agent.jsonChoose the policy
Decide what the agent may spend: most per call and most per period, both counting the fee, how long a period lasts, whom it may pay, and when the policy ends. Writing a policy helps choose. This page uses 0.5 USDC per call, 2 USDC a day, open counterparties and no expiry.
Charter it
At /app, connect the wallet and sign in, then press Charter an agent. Fill the card, choose Make one in this browser or Paste a public key, set the policy and the deposit, give the key's consent, and press Build the charter on the review. The wallet signs once. The console walks through each step.
The CLI signs with the principal's keypair file and sends the transaction itself. With --api it posts the card to the API first, and --agent-keypair has the agent's key file sign its consent on the spot.
npx civitas charter --keypair principal.json --agent-keypair agent.json \
--name "Research agent" --endpoint https://agent.example/ --offers "Buys market data" \
--max-per-call 500000 --max-per-period 2000000 --period-seconds 86400 \
--deposit 2000000 --api "$CIVITAS_API_URL"It prints the transaction's signature, the agent key, and the card's cardHash and cardUri. When the agent's key file sits with someone else, they run civitas consent with your address and the card's hash, and you pass what it prints as --agent, --consent-signature and --consent-expires-at; the CLI reference has both runs.
Sign in with the wallet, post the card, build the charter, sign it with the wallet, then submit and follow it.
import { createClient, toBase58 } from '@civitas/contract'
import { signConsent } from '@civitas/program'
import { Keypair, PublicKey } from '@solana/web3.js'
declare const apiUrl: string, agent: Keypair
declare function signIn(input: unknown): Promise<{ publicKey: string; signedMessage: string; signature: string }>
declare function signTransaction(transactionBase64: string): Promise<string>
const open = createClient(apiUrl)
const { input, nonceToken } = await open.signInNonce()
const session = await open.verifySignIn({ ...(await signIn(input)), nonceToken })
const api = createClient(apiUrl, { headers: { Authorization: `Bearer ${session.token}` } })
const card = await api.postCard({ name: 'Research agent', endpoint: 'https://agent.example/', offers: 'Buys market data' })
// the agent key consents to this principal and this card, for the next hour
const expiresAt = Math.floor(Date.now() / 1000) + 3600
const consent = signConsent(agent.secretKey, {
principal: new PublicKey(session.wallet),
agentKey: agent.publicKey,
cardHash: Buffer.from(card.hash, 'hex'),
expiresAt: BigInt(expiresAt),
})
const build = await api.buildCharter({
agentKey: agent.publicKey.toBase58(),
consent: { signature: toBase58(consent), expiresAt: new Date(expiresAt * 1000).toISOString() },
cardHash: card.hash,
cardUri: card.uri,
policy: { perCall: '500000', perPeriod: '2000000', periodSeconds: 86_400, counterparties: null, expiry: null },
firstDeposit: '2000000',
})
console.log(build.review.summary)
const signedTransactionBase64 = await signTransaction(build.transactionBase64)
await api.submit({ mode: 'relay', buildId: build.id, signedTransactionBase64, idempotencyKey: crypto.randomUUID() })
const status = await api.follow(build.id) // submitted, then confirmed or failedThe wallet's signIn takes the Sign-In With Solana input and returns the signed message and signature as base64. signConsent comes from @civitas/program; whoever holds the agent key can run that part and send back the signature and expiry. The routes are under REST API.
Check it
The agent is active. Its page at /agents/<agent key> shows the principal, the card, policy version 1 and a vault of 2 USDC, and the console at /app lists it with its spending this period against the cap.