Skip to main content

Batch writes

Version: V2
View Markdown

Create several terms and seed their vaults in dependency order, checking the result of each transaction before pricing the next one.

Prompt for your agentRun batch writes in dependency order
Goal: create many atoms and triples from my dataset in dependency order, one reviewed stage at a time.
Read https://docs.intuition.systems/docs/build/batch-writes.md, https://docs.intuition.systems/docs/build/create-atoms.md and https://docs.intuition.systems/docs/build/create-triples.md.
Use exact package versions from https://docs.intuition.systems/intuition-release.json and public entry points only.
Input: [my CSV or JSON of entities and relationships].
Derive every ID offline first and skip terms that already exist. Put atoms before the triples that use them, and keep each stage within the MultiVault batch limit.
For each stage, prepare the call and stop. Show me the stage contents, value and expected IDs, and wait for my approval. Never sign or send anything yourself.
Save every confirmed receipt so a failed run can resume after the last confirmed stage. Quote deposits only after their terms exist.
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, Create atoms and Create triples. Use a compatible MultiVault, a funded signer and the same interactive session for each stage. Set aside gas for each transaction. The example’s signer creates the terms and receives the seed shares. Complete stage helper

Steps​

1. Split inputs at their dependencies​

For example, to create Alice, “follows” and Bob, then create “Alice follows Bob” and fund its vault, prepare three stages. Batch the missing atoms first. Use their primary bytes to derive the IDs. After their original successful receipt, prepare the triple with those IDs. After the triple’s receipt, preview and seed its vault. Create any nested triples in dependency order, waiting for each prerequisite transaction.

The read-backed multivaultCreateAndSeedTerm action can return create-atoms, create-triples and deposit-batch steps in that order, with per-leg previews and a totalValue. Planning reads current state. A triple preview can run before its input terms exist and use fee assumptions that change once they do. Triple execution checks all three terms. A deposit preview for a term that has yet to be created reverts. Prepare each dependent stage against confirmed state. SDK planner · MultiVault previews

2. Build one bounded stage​

The helper accepts a kind and its rows. For atoms, pass the primary byte strings. For triples, pass ordered subject, predicate and object IDs. For seeds, pass the target term, curve, gross native wei and slippage in basis points for each leg. Each nonempty stage must fit the deployment’s MAX_BATCH_SIZE. Align inputs by index and keep each term/curve pair unique in a seed batch. If one leg could materially change the next leg’s quote, submit them separately.

  if (stage.kind === 'atoms') {
unique(stage.rows);
const assetsIn = await multiVaultGetAtomCost(s);
const atomsToCreate = await Promise.all(
stage.rows.map(async (data) => ({
data,
assetsIn,
termId: await checkAtomData(s, data),
})),
);
return multivaultCreateAndSeedTerm(s, { receiver, atomsToCreate });
}
if (stage.kind === 'triples') {
const assetsIn = await multiVaultGetTripleCost(s);
const triplesToCreate = await Promise.all(
stage.rows.map(async (roles) => ({
...roles,
assetsIn,
termId: (await checkTriple(s, roles)).tripleId,
})),
);
unique(triplesToCreate.map((triple) => triple.termId));
return multivaultCreateAndSeedTerm(s, { receiver, triplesToCreate });
}
unique(stage.rows.map((seed) => seed.termId + '/' + seed.curveId));
const exists = await Promise.all(
stage.rows.map(({ termId }) =>
multiVaultIsTermCreated(s, { args: [termId] }),
),
);
if (!exists.every(Boolean))
throw new Error('Wait for creation before quoting this deposit.');
const plan = await multivaultCreateAndSeedTerm(s, {
receiver,
seedDeposits: stage.rows,
});

At creation the helper pays the current per-item creation cost. For seeds, choose the actual gross assets to deposit, check the encoded minShares on every leg and reserve the sum as payment. Output estimates are per leg. The contract decides whether the batch can execute at those minima.

3. Review and send this stage​

Call submitStage(session, stage) once for the stage you intend to send. Read the chain, MultiVault, signer, receiver, term bytes or ordered IDs, decoded arguments, calldata and exact native value in the terminal. The helper accepts exactly one planned step, simulates its complete calldata, prompts for that operation and records its submitted hash.

  const tx = { to: s.address, data: step.calldata, value: plan.totalValue };
const call = decodeFunctionData({ abi: MultiVaultAbi, data: tx.data });
await s.publicClient.call({ ...tx, account: s.signer });
await review(s, step.type.toUpperCase(), {
receiver: plan.receiver,
stage,
call,
plan,
...tx,
});
const hash = await s.walletClient.sendTransaction({
...tx,
account: s.walletClient.account!,
chain: s.walletClient.chain,
});
const receipt = await waitForOriginal(s, hash);

The complete helper matches creation events to the expected IDs and seed events to the receiver, term, curve, payment and minimum shares. Use its returned receipt and plan as your record before preparing the next stage.

Check the result​

An individual batch call reverts as a unit. Earlier transactions persist if a later transaction fails. For the example above, you should have a successful atom receipt, a successful triple receipt, and then a separate successful deposit receipt. Verify each against the original hash and selected MultiVault address. Read the final receiver’s share balance for the seeded term and curve. Deposit and redeem

Troubleshooting​

If confirmation times out or the wallet replaces a transaction, resolve its original hash and any replacement first. If the atom stage succeeded and triple creation reverted, keep the atom receipt. Check whether the triple now exists, derive only the outstanding work, read costs again and review a new transaction. For deposits, inspect the original receipt’s deposit events before retrying: a second successful submission would deposit a second time.

Build action plans and envelopes · Route writes through the FeeProxy · Protocol write lifecycle

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