Guides

The CLI

Run a whole Civitas economy from a shell with civitas: keys, charters, funding, policies, a paid service and a paying agent.

civitas does the principal's work and the builder's from a shell. Principal commands sign with a keypair file and send the transaction straight to a Solana RPC; pay and serve run the two SDKs.

Set it up

bash
npm install ./civitas-contract-0.2.0.tgz ./civitas-program-0.2.0.tgz ./civitas-agent-0.2.0.tgz ./civitas-service-0.2.0.tgz ./civitas-cli-0.2.0.tgz
export SOLANA_RPC_URL=<your RPC>
export CIVITAS_API_URL=<the Civitas API>
export CLUSTER=mainnet

Four flags have environment defaults: --rpc reads SOLANA_RPC_URL, --api reads CIVITAS_API_URL, --cluster reads CLUSTER, and --keypair reads CIVITAS_KEYPAIR_PATH. Amounts are integer base units, so 1000000 is 1 USDC.

From keys to a paid call

Make the keys

bash
npx civitas keygen --out payer.json
npx civitas keygen --out service-agent.json
npx civitas keygen --out submitter.json

principal.json and other-principal.json are two existing wallets holding USDC and SOL. --agent-keypair has each agent's key file sign its consent to the charter; for a key held by someone else, civitas consent makes the consent on their side. The service gets a principal of its own because a payment between two agents of the same principal is classed self. Fund submitter.json with SOL.

Charter both agents

bash
npx civitas charter --keypair principal.json --agent-keypair payer.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

npx civitas charter --keypair other-principal.json --agent-keypair service-agent.json \
  --name "Sample feed" --endpoint http://127.0.0.1:18080/feed --offers "A sample JSON feed" \
  --max-per-call 0 --max-per-period 0 --period-seconds 86400

Serve and list the feed

bash
npx civitas serve --keypair service-agent.json --principal <other principal key> --submitter submitter.json --price 100000 --port 18080
npx civitas list --keypair other-principal.json --agent <service agent key> --endpoint http://127.0.0.1:18080/feed --price 100000

serve runs a sample JSON feed at http://127.0.0.1:18080/feed until it is stopped. --principal is the public key of other-principal.json, which chartered the service agent; serve checks it against the charter before it starts. Leave it running in its own shell.

Pay a call

bash
npx civitas pay http://127.0.0.1:18080/feed --keypair payer.json --max-per-call 500000 --json

It prints the response's status and body, the payment with the settlement signature and receipt, and latencyMs from the 402 to the paid response. A real run's output is under pay.

Managing an agent

bash
npx civitas fund --keypair principal.json --agent <payer key> --amount 1000000
npx civitas policy --keypair principal.json --agent <payer key> --max-per-call 250000 --max-per-period 1000000 --period-seconds 86400
npx civitas freeze --keypair principal.json --agent <payer key>
npx civitas unfreeze --keypair principal.json --agent <payer key>
npx civitas withdraw --keypair principal.json --agent <payer key> --amount 500000
npx civitas revoke --keypair principal.json --agent <payer key>

policy replaces the whole policy: leave out --counterparty and the new policy is open. fund works from any wallet, and the deposit records it as the funder.

In scripts

--json prints one JSON object per command and, on failure, { "error": "<name>", "message": "<detail>" } on stderr with exit code 1. A program refusal keeps its name:

bash
if ! out=$(npx civitas pay "$URL" --keypair payer.json --json 2>&1); then
  echo "$out" | grep -q '"error":"OverPeriodCap"' && echo "budget spent for this period"
fi