CLI anchoring tutorial

Anchor demo data on staging, with optional queries for existing protocol records

CLI command reference

Submit a data anchor to staging, then optionally query submission status, contributions, DIDs, and tasks.

Requirements: macOS, Homebrew, and jq. The configuration below includes the public API key of the helloworld demo App on staging. No separate credential file or App provisioning is required. Use this demo App for test data only; its credentials and demo records are shared with other participants.

If your goal includes Record issuance, start with the staging trial prerequisites. The shared demo App covers the anchor step. Issuance also needs an enrolled App, a Producer signer, prepaid storage, approved source rights and an allocation.

1. Install

brew install humanbased-ai/tap/xny
xny version
xny record issue --help
xny record members --help

For Record issuance use v0.2.18 or later. Upgrade with brew update and brew upgrade humanbased-ai/tap/xny.

jq prepares the anchor JSON and checks receipts; the optional queries do not require it. If jq --version reports no command, install jq with your package manager, for example:

brew install jq

2. Configure authentication

Configure the shared staging credential, create the helloworld-demo profile, and verify authentication:

export XNY_API_KEY=pk_live_PKN2j2QjQDr3sFdlR1UCHySQWTgJkcZl
unset XNY_API_URL XNY_PROFILE
xny profile add helloworld-demo --url https://cloud.staging.xny.ai
printf '%s\n' "$XNY_API_KEY" | xny auth login --profile helloworld-demo
xny profile use helloworld-demo
unset XNY_API_KEY
xny auth status --profile helloworld-demo --output json

The expected App ID is 2480520856900000000. Cloud identifies the App from the API key. The key is saved in the operating system's keychain, and the service URL is saved in the profile. Both remain available after restarting the terminal.

3. Prepare data

DEMO_TEXT is the text to submit. Each run creates a separate directory containing the payload, metadata, and idempotency key.

DEMO_TEXT='Hello, this is my first XnY record!'
DEMO_RUN="$(uuidgen)"
mkdir "$DEMO_RUN"
cd "$DEMO_RUN"
printf '%s\n' "$DEMO_RUN" > idempotency-key.txt
date -u '+%Y-%m-%dT%H:%M:%SZ' > prepared-at.txt
jq -n --arg text "$DEMO_TEXT" '{message:$text,source:"helloworld-cli-demo"}' > payload.json
jq -n \
  --arg submission "$DEMO_RUN" \
  --arg task "helloworld-demo-task" \
  --arg did "181348315960027670548318242565301745050" \
  --arg published "$(cat prepared-at.txt)" \
  '{submission_id:$submission,task_id:$task,contributor_did_id:$did,
    publisher:("did:xny:"+$did),published_at:$published,
    kind:"SAMPLE",verdict:0,grade:0,tags:{application:"helloworld-cli-demo"}}' > metadata.json
shasum -a 256 metadata.json payload.json > inputs.sha256
cat payload.json

The example uses the demo App's shared task and DID to anchor simulated data on Base Sepolia. Keep the input files unchanged after submission.

Cloud authorizes the App, not the DID or task: any App with app:write can anchor to any task and name any contributor DID. Creating a task or DID through one App does not stop other Apps from writing to it.

Deduplication depends on the idempotency key and the complete request, not just the payload. Running this step again generates a new submission ID, timestamp, and idempotency key. It creates a new submission that can produce another on-chain transaction. To retry the same submission, see Optional: verify idempotent replay.

4. Anchor the data

Submit the data and save the job ID:

xny anchor push --profile helloworld-demo \
  --metadata metadata.json --payload payload.json \
  --content-type application/json \
  --idempotency-key "$(cat idempotency-key.txt)" \
  --no-wait --output json > submission.json &&
jq -er '.operation.job_id' submission.json > job-id.txt
cat submission.json

A successful response means the request was accepted. Poll every five seconds, up to 120 times. Polling stops on finalization, a terminal failure, or a request error:

for attempt in {1..120}; do
  xny anchor status "$(cat job-id.txt)" --profile helloworld-demo --output json > receipt.json || break
  DEMO_STATUS="$(jq -r '.status' receipt.json)"
  printf 'Status: %s\n' "$DEMO_STATUS"
  if [ "$DEMO_STATUS" = finalized ]; then break; fi
  sleep 5
done
cat receipt.json
jq -e '.status == "finalized" and .chain_id == 84532' receipt.json

In v0.1.2, terminal failures return a nonzero exit code. Pending status queries can still exit zero, so check the receipt status to confirm completion.

The final check should print true: the status is finalized and the chain ID is 84532. If the job is still pending, run the polling block again. A successful receipt contains tx_hash and onchain_entity_id; view the transaction in the Base Sepolia explorer.

Keep the original payload and the finalized onchain_entity_id (CF ID). With an enrolled issuing App, continue to issue a Record and verify its initial ownership. Queries and replay verification below are optional.

Optional queries

These commands query existing demo records and can run independently after authentication. They do not query the new submission created in step 4.

Submission execution status

xny anchor status ad9d33a3-5fb3-45ba-b7b1-ea82618e25bb --profile helloworld-demo --output json

The expected status is finalized. anchor status takes a job_id; there is currently no separate command to look up a submission by its business submission_id.

Contribution and lineage

Read an existing on-chain contribution:

xny query contributions detail --profile helloworld-demo \
  --contribution-id 0x102937abdd68a96b7946c466547d6991195c45c0935c2c260171c53504b2c5a8 --output json

Read the lineage of the same contribution:

xny query contributions lineage --profile helloworld-demo \
  --contribution-id 0x102937abdd68a96b7946c466547d6991195c45c0935c2c260171c53504b2c5a8 \
  --direction both --depth 2 --node-limit 50 --output json

This SAMPLE has no parent contribution, so its graph contains only itself and no edges. truncated: true indicates that the result was truncated.

DID contributions and holdings

List contributions for the demo DID:

xny query dids contributions --profile helloworld-demo \
  --did-id 181348315960027670548318242565301745050 --page-size 10 --output json

List holdings for the same DID:

xny query dids holdings --profile helloworld-demo \
  --did-id 181348315960027670548318242565301745050 --page-size 10 --output json

The contribution list contains records from the shared demo DID. Holdings can be empty; anchoring does not automatically grant Dataset shares.

Task, Campaign, and Frontier

Read the demo task:

xny query tasks detail --profile helloworld-demo \
  --task-id 0x2b8f8a96d394e76285c4b9212473325e70887092c0c74d952fe3c9df5e0deec2 --output json

List contributions under the task:

xny query tasks contributions --profile helloworld-demo \
  --task-id 0x2b8f8a96d394e76285c4b9212473325e70887092c0c74d952fe3c9df5e0deec2 --page-size 10 --output json

Read its Campaign:

xny query campaigns detail --profile helloworld-demo \
  --campaign-id 0x8336ba0647a69dea41b3df2fe24606ff53875db5aa289130befe42a6e536c841 --output json

Read its Frontier:

xny query frontiers detail --profile helloworld-demo \
  --frontier-id 0xa72b07d1efffd59e30788d4243d62eb7971083c9b21d4bf749e303a60126678d --output json

Task queries use a bytes32 on-chain ID, while submission metadata uses the business task ID helloworld-demo-task. The on-chain ID is the Keccak-256 hash (Ethereum keccak256) of the business ID's UTF-8 bytes. List commands return one page of results.

Optional: verify idempotent replay

Within 24 hours of preparing the data, retry with the same files and idempotency key:

shasum -a 256 -c inputs.sha256 &&
xny anchor push --profile helloworld-demo --metadata metadata.json --payload payload.json \
  --content-type application/json \
  --idempotency-key "$(cat idempotency-key.txt)" \
  --no-wait --output json > replay.json &&
jq -e --arg job "$(cat job-id.txt)" '.operation.job_id == $job' replay.json

A result of true confirms that the response contains the same job ID. A replay may return the original queued response; use anchor status for the current status. Do not use this replay step to resubmit old data after 24 hours.

Keep the input files and receipts in the submission directory. To submit new data, run cd .. and start again at step 3.

Last updated

On this page