Skip to main content

Create Triple

[Problem Internal Link] are higher-order structures in the Intuition system, used to define relationships between Atoms. Each Triple consists of three components - Subject, Predicate, and Object - all represented as Atoms, enabling precise, machine-readable representations of data relationships.

Context

The createTriple and batchCreateTriple functions are part of the [Problem Internal Link] contract, which manages the creation and relationships between Atoms through Semantic Triples. When creating Triples, each component must reference existing Atom vault IDs. The Triple structure enables:

  • Many-to-one attestations
  • Positive and negative signaling through triple vaults
  • Flat data structures for optimal scalability

For example, a Triple might represent:

  • Subject: "Bob" (Atom ID: "1")
  • Predicate: "is" (Atom ID: "2")
  • Object: "Trustworthy" (Atom ID: "3")

createTriple

function createTriple(
uint256 subjectId,
uint256 predicateId,
uint256 objectId
) external payable nonReentrant whenNotPaused returns (uint256)

Parameters

  • subjectId: vault ID of the Atom representing the subject
  • predicateId: vault ID of the Atom representing the predicate/relationship
  • objectId: vault ID of the Atom representing the object
  • value : Initial deposit into the Triple’s positive multivault. Must be ≥ to the triple creation cost.
  • Returns: uint256 - Created triple vault ID

Implementation

// useCreateTriple Hook
import { type GetContractReturnType } from 'viem'
import { base } from 'viem/chains'
import { useContractWriteAndWait } from './useContractWriteAndWait'
import { useMultivaultContract } from './useMultivaultContract'

export const useCreateTriple = () => {
const multivault = useMultivaultContract(
base.id
) as GetContractReturnType

return useContractWriteAndWait({
...multivault,
functionName: 'createTriple',
})
}
// Usage Example
const {
writeAsync: writeCreateTriple,
awaitingWalletConfirmation,
awaitingOnChainConfirmation,
} = useCreateTriple()

async function handleCreateTriple(subjectId: string, predicateId: string, objectId: string) {
if (!awaitingOnChainConfirmation && !awaitingWalletConfirmation && writeCreateTriple) {
try {
const tx = await writeCreateTriple({
address: MULTIVAULT_CONTRACT_ADDRESS,
abi: multivaultAbi,
functionName: 'createTriple',
args: [BigInt(subjectId), BigInt(predicateId), BigInt(objectId)],
value: tripleCost, // Must be >= minimum creation cost
})

if (tx?.hash) {
const receipt = await publicClient.waitForTransactionReceipt({
hash: tx.hash,
})
// Handle success
}
} catch (error) {
// Handle error
}
}
}

createBatchTriple

function createTripleBatch(
uint256[] calldata subjectIds,
uint256[] calldata predicateIds,
uint256[] calldata objectIds
) external payable nonReentrant whenNotPaused returns (uint256[] memory)

Parameters

  • subjectIds: vault ID(s) of the Atom representing the subjects
  • predicateIds: vault ID(s) of the Atom representing the predicate/relationships
  • objectIds: vault ID(s) of the Atom representing the objects
  • value : Initial deposit into the triples’ multivaults. Must be ≥ to the atom creation cost * length of triples. This will get distributed evenly across all created triples.
  • Returns uint256[] - Created triples’ vault ID(s)

Implementation

// useBatchCreateTriple Hook
import { type GetContractReturnType } from 'viem'
import { base } from 'viem/chains'
import { useContractWriteAndWait } from './useContractWriteAndWait'
import { useMultivaultContract } from './useMultivaultContract'

export const useBatchCreateTriple = () => {
const multivault = useMultivaultContract(
base.id
) as GetContractReturnType

return useContractWriteAndWait({
...multivault,
functionName: 'createTripleBatch',
})
}
// Usage Example
const {
writeAsync: writeBatchCreateTriple,
awaitingWalletConfirmation,
awaitingOnChainConfirmation,
} = useBatchCreateTriple()

async function handleBatchCreateTriple(
subjectIds: string[],
predicateIds: string[],
objectIds: string[]
) {
const value = BigInt(tripleValue) * BigInt(subjectIds.length)
if (!awaitingOnChainConfirmation && !awaitingWalletConfirmation && writeBatchCreateTriple) {
try {
const tx = await writeBatchCreateTriple({
address: MULTIVAULT_CONTRACT_ADDRESS,
abi: multivaultAbi,
functionName: 'createTripleBatch',
args: [
subjectIds.map(BigInt),
predicateIds.map(BigInt),
objectIds.map(BigInt),
],
value: tripleCost * subjectIds.length, // Must be >= minimum creation cost * number of triples
})

if (tx?.hash) {
const receipt = await publicClient.waitForTransactionReceipt({
hash: tx.hash,
})
// Handle success
}
} catch (error) {
// Handle error
}
}
}

Cost Considerations

  1. Creation Cost:
    • Minimum ETH required to create a Triple
    • Retrieved via getTripleCost()
    • Includes protocol fee sent to treasury
    • Must be included in transaction's value parameter
  2. Initial Deposit:
    • Any ETH sent above the creation cost
    • Deposited into the positive vault
    • Subject to entry fees

See also:

  • [Problem Internal Link]
  • [Problem Internal Link]