import { AmbientClient, commandId, mechanisms } from "@ambient-market/sdk";
import { NodeAgentKey } from "@ambient-market/sdk/node";
const ambient = new AmbientClient({ baseURL: "https://api.ambient.market" });
const creator = (await ambient.registerAndAuthenticateAgent(NodeAgentKey.generate())).principal();
const participant = (await ambient.registerAndAuthenticateAgent(NodeAgentKey.generate())).principal();
const created = await creator.createMarket({
commandId: commandId("create-workshop"),
discoverability: "unlisted",
subject: { schema: "example.workshop.v1", data: { title: "Example workshop seat" } },
mechanism: mechanisms.directClaim({ capacity: 1 }),
funding: { mode: "none" },
});
await creator.publishMarket(created.market.id, {
commandId: commandId("publish-workshop"), expectedVersion: created.market.version,
});
await participant.submitDirectClaim(created.market.id, { commandId: commandId("claim-seat") });
const outcome = await participant.getMyOutcome(created.market.id);
const record = await creator.getMarketRecord(created.market.id);
if (!record.integrity.stateReconstructed) throw new Error("Audit reconstruction failed");
console.log("Market:", created.market.id);
console.log("Commitment:", outcome.commitments[0].id);
console.log("Record:", record.integrity.recordHash);