Skip to main content

Create triples

Version: V2
View Markdown

Create a relationship from three existing term IDs and verify the base triple and its counter on the default curve.

Prompt for your agentPrepare a triple creation and check both vaults
Goal: create one triple on Intuition testnet and confirm both its vault and its counter vault.
Read https://docs.intuition.systems/docs/build/create-triples.md, https://docs.intuition.systems/docs/concepts/triples.md and https://docs.intuition.systems/docs/contracts/multivault.md.
Use exact package versions from https://docs.intuition.systems/intuition-release.json and public entry points only.
Input: subject, predicate and object term IDs, in that order.
Confirm that all three terms exist on the selected MultiVault. Derive the triple and counter-triple IDs and check whether the triple already exists.
Read the triple cost. Prepare the call, then stop. Show me the chain, contract, signer, term IDs, value and expected triple ID, and wait for my approval. Never sign or send it yourself.
After I submit it, read the triple and counter-triple vaults on the default curve and report what each holds.
Report the checks you actually ran and anything you could not verify.

Paste this into your coding agent. It points the agent at the Markdown version of each page and leaves every signature to you.

Before you start​

Follow Install and pin the packages and Create atoms. Use the same chain, MultiVault and funded signer for your reads and write. Keep the three term IDs in subject, predicate, object order. The helper accepts a session plus an object with subjectId, predicateId and objectId. Example source

Steps​

1. Confirm each term and derive the pair​

For a simple claim such as “Alice follows Bob,” resolve Alice, the predicate and Bob to existing atom IDs on this MultiVault. You can also place an already-created triple or counter-triple in any slot. A deterministically computed ID still needs to exist on the selected chain. The contract checks all three slots with the same term-existence rule. MultiVault term validation

  const tripleId = calculateTripleId(subjectId, predicateId, objectId);
const counterId = calculateCounterTripleId(tripleId);
const [subject, predicate, object, exists] = await Promise.all(
[subjectId, predicateId, objectId, tripleId].map((id) =>
multiVaultIsTermCreated(s, { args: [id] }),
),
);
if (!subject || !predicate || !object)
throw new Error('Create missing terms first.');
if (exists) throw new Error('This ordered triple already exists.');

calculateTripleId hashes the ordered IDs with the triple salt. Reversing the subject and object describes a different claim. calculateCounterTripleId derives the opposing side from the base ID and a distinct salt. ID derivation

2. Review and fund the base creation​

Read multiVaultGetTripleCost and reserve gas. The live cost covers the creation fee and bootstrap for both vaults. The example allocates exactly that cost, with no extra user stake. Each input array has one item per triple. For an array of relationships, align each subject, predicate, object and payment by index and send the sum of the allocations.

  const { tripleId, counterId } = await checkTriple(s, {
subjectId,
predicateId,
objectId,
});
const cost = await multiVaultGetTripleCost(s);
const args = [[subjectId], [predicateId], [objectId], [cost]] as const;
const calldata = multiVaultCreateTriplesEncode(
[subjectId],
[predicateId],
[objectId],
[cost],
);
await review(s, 'CREATE TRIPLE', {
to: s.address,
creator: s.signer,
subjectId,
predicateId,
objectId,
tripleId,
counterId,
args,
calldata,
value: cost,
});
const hash = await multiVaultCreateTriples(s, { args, value: cost });
const receipt = await waitForOriginal(s, hash);

3. Inspect both vaults​

One base transaction records the same ordered tuple for both IDs, links the counter to the base, and initializes the default-curve vault on each side. The counter receives its minimum bootstrap shares at the burn address. The creator’s optional additional stake goes into the base vault. A separate counter creation is unnecessary.

Check the result​

Save the submitted hash. On its original successful receipt, filter by the MultiVault address and find TripleCreated with the signer as creator, the expected base ID and all three ordered term IDs. Expect one creation event for this relationship. Read isTermCreated for both IDs on the same contract. The helper returns both IDs and the verified receipt. Triple and counter initialization

Troubleshooting​

If a slot is missing, finish that term’s creation and check its receipt first. If another writer created the same triple, verify its tuple and use the existing ID. On a cost or simulation failure, re-read the contract and review a new call. Resolve an unknown, replaced or reverted transaction from its hash before retrying.

Triples · Batch writes · SDK MultiVault actions

Applies to V2 · @0xintuition/protocol 4.1.0 · @0xintuition/sdk 4.1.0 · @0xintuition/ids 0.1.1