Working with Primitives
This guide shows how to create and interact with atoms, triples, and vaults using the Protocol package (low-level contract interactions).
For conceptual understanding: Primitives Overview
Creating Atomsβ
Atoms are unique identifiers for any entity. Here's how to create them with the Protocol package:
import { multiVaultCreateAtoms } from '@0xintuition/protocol'
import { createPublicClient, createWalletClient, http } from 'viem'
// Setup clients
const publicClient = createPublicClient({
chain: intuitionTestnet,
transport: http(),
})
const walletClient = createWalletClient({
chain: intuitionTestnet,
transport: http(),
account: yourAccount,
})
// Create an atom from a string
const atomData = {
value: 'TypeScript',
}
const tx = await multiVaultCreateAtoms({
publicClient,
walletClient,
atoms: [atomData],
})
console.log('Atom created:', tx.atomIds[0])
See also: Atoms Concept
Creating Triplesβ
Triples connect three atoms to create structured claims:
import { multiVaultCreateTriples } from '@0xintuition/protocol'
// Create a triple: [Alice] - [knows] - [Bob]
const tripleData = {
subjectId: aliceAtomId,
predicateId: knowsAtomId,
objectId: bobAtomId,
}
const tx = await multiVaultCreateTriples({
publicClient,
walletClient,
triples: [tripleData],
})
console.log('Triple created:', tx.tripleIds[0])
See also: Triples Concept
Vault Operationsβ
Every atom and triple has an associated vault for staking:
Depositing (Signaling Support)β
import { multiVaultDeposit } from '@0xintuition/protocol'
// Deposit into an atom's vault
const depositTx = await multiVaultDeposit({
publicClient,
walletClient,
vaultId: atomVaultId,
amount: parseEther('1.0'), // 1 TRUST token
})
console.log('Deposited into vault:', depositTx.shares)
Redeeming (Withdrawing)β
import { multiVaultRedeem } from '@0xintuition/protocol'
// Redeem shares from a vault
const redeemTx = await multiVaultRedeem({
publicClient,
walletClient,
vaultId: atomVaultId,
shares: sharesAmount,
})
console.log('Redeemed assets:', redeemTx.assets)
Querying Vault Detailsβ
import { getVaultDetails } from '@0xintuition/protocol'
const vaultDetails = await getVaultDetails({
publicClient,
vaultId: atomVaultId,
})
console.log('Total assets:', vaultDetails.totalAssets)
console.log('Total shares:', vaultDetails.totalShares)
console.log('Share price:', vaultDetails.currentSharePrice)
See also: Signals Concept
Batch Operationsβ
Create multiple atoms or triples in a single transaction:
// Batch create atoms
const atoms = [
{ value: 'TypeScript' },
{ value: 'React' },
{ value: 'Solidity' },
]
const batchTx = await multiVaultCreateAtoms({
publicClient,
walletClient,
atoms,
})
console.log('Created atom IDs:', batchTx.atomIds)
Counter-Triplesβ
Create opposing claims (for/against):
// Original claim
const claim = {
subjectId: contractAtomId,
predicateId: isSafeAtomId,
objectId: trueAtomId,
}
// Counter-claim (opposing)
const counterClaim = {
subjectId: contractAtomId,
predicateId: isSafeAtomId,
objectId: falseAtomId,
}
Eventsβ
Listen for primitive creation events:
import { parseAtomCreatedEvent, parseTripleCreatedEvent } from '@0xintuition/protocol'
// Watch for atom creation
publicClient.watchContractEvent({
address: multiVaultAddress,
abi: multiVaultAbi,
eventName: 'AtomCreated',
onLogs: (logs) => {
logs.forEach((log) => {
const event = parseAtomCreatedEvent(log)
console.log('New atom:', event.atomId, event.data)
})
},
})
Examplesβ
See complete examples:
SDK Alternativeβ
For a higher-level API with React hooks, see:
API Referenceβ
Full API documentation: