Skip to main content

Connect to a network

Version: V2
View Markdown

Connect a read-only client to Intuition mainnet, testnet, or local Anvil and verify the MultiVault by reading its atom creation cost.

Prompt for your agentVerify a network and read its atom creation cost
Goal: write a read-only script that proves my app is talking to the right Intuition network.
Read https://docs.intuition.systems/docs/build/connect.md, https://docs.intuition.systems/docs/reference/networks.md and https://docs.intuition.systems/docs/contracts/deployments.md.
Use exact package versions from https://docs.intuition.systems/intuition-release.json and public entry points only.
Network: Intuition testnet, chain 13579, unless I say otherwise. Resolve the MultiVault address for that chain from the deployments package.
Before any contract call, read the RPC chain ID and stop with a clear error if it does not match.
Then read getAtomCost and getAtomUriConfig from MultiVault and print them, with the cost in both wei and TRUST.
Make no writes and request no signatures.
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​

Use Node 22.21.0 and the dependencies in the pinned install guide. The commands below run from a checkout of the docs repository containing the example. Install its dependencies with npm ci --prefix examples/v2 --ignore-scripts. For Anvil, complete the deployment step in Test locally first. The helper needs only the public RPC and contract address. Complete connection helper.

Steps​

1. Choose the chain and deployment together​

TargetChain IDRPC seen by the callerMultiVault source
Intuition mainnet1155https://rpc.intuition.systems/httpMainnet package entry
Intuition testnet13579https://testnet.rpc.intuition.systems/httpTestnet package entry
Local Anvil31337http://localhost:8545 on the host, http://anvil:8545 inside Core's Compose network.MultiVault from your completed deployment's devnet/deployments-devnet.json

The deployments package resolves an override for the named contract and chain first, then consults its built-in table. A missing entry throws. The package has no built-in MultiVault for 31337, so copy the proxy address generated for your running Anvil. Network definitions and address lookup.

import {
getMultiVaultAddressFromChainId,
intuitionMainnet,
intuitionTestnet,
} from '@0xintuition/deployments';
import { multiVaultGetAtomCost } from '@0xintuition/protocol';
import {
createPublicClient,
getAddress,
http,
isAddress,
zeroAddress,
} from 'viem';
import { foundry } from 'viem/chains';

export function networkSettings(args: string[]) {
const [name, deployedAddress] = args;
if (args.length === 1 && (name === 'mainnet' || name === 'testnet')) {
const chain = name === 'mainnet' ? intuitionMainnet : intuitionTestnet;
return {
chain,
rpc: chain.rpcUrls.default.http[0],
address: getMultiVaultAddressFromChainId(chain.id),
};
}

if (args.length !== 2 || (name !== 'local' && name !== 'local-container'))
throw new Error(
'Choose mainnet, testnet, local ADDRESS or local-container ADDRESS.',
);
if (
deployedAddress?.length !== 42 ||
!isAddress(deployedAddress) ||
deployedAddress === zeroAddress
)
throw new Error(
'Supply the MultiVault proxy address from your local deployment.',
);
return {
chain: foundry,
rpc: name === 'local' ? 'http://localhost:8545' : 'http://anvil:8545',
address: getMultiVaultAddressFromChainId(foundry.id, {
MultiVault: { [foundry.id]: getAddress(deployedAddress) },
}),
};
}

2. Verify the chain before calling the contract​

The client asks the RPC for its actual chain ID. After a match, multiVaultGetAtomCost reads the selected MultiVault's base creation cost in wei. Run one command for your chosen network.

export async function connect(args: string[]) {
const { chain, rpc, address } = networkSettings(args);
const publicClient = createPublicClient({
chain,
transport: http(rpc, { timeout: 5000, retryCount: 0 }),
});
const actual = await publicClient.getChainId();
if (actual !== chain.id)
throw new Error(
`Expected chain ${chain.id}, but the RPC returned ${actual}.`,
);
const atomCost = await multiVaultGetAtomCost({ publicClient, address });
return {
chainId: actual,
multiVault: address,
atomCostWei: atomCost.toString(),
};
}
node examples/v2/first-write/src/connect-guide.ts testnet

Use mainnet for mainnet. For a local read on your host, set CORE_DIR to your Core checkout and use the file produced by the successful deployment job. With jq installed, run the following command from the docs checkout.

vault=$(jq -er 'select(.chainId == 31337) | .MultiVault' "$CORE_DIR/devnet/deployments-devnet.json") &&
node examples/v2/first-write/src/connect-guide.ts local "$vault"

An application running inside the same Compose network can use local-container with that address. Anvil's service name resolves there. A browser or Node process running on the host uses localhost.

Check the result​

The CLI prints chainId, multiVault and a decimal string named atomCostWei. Compare the chain ID to the table and, on Anvil, the proxy to the generated deployment file. The observed cost belongs to that contract at read time. Mainnet uses TRUST and testnet uses tTRUST, each with 18 decimal places. Public deployment table.

Troubleshooting​

ResultWhat to check
Unexpected chain IDConfirm which RPC the selected environment reaches.
Connection refused on 31337Check Anvil is running and choose the hostname for your calling process.
Missing address, empty return data, or reverted readVerify the proxy belongs to this chain and still has the expected contract after any local redeployment.

Protocol writes explains what changes when you introduce a signer. To read indexed atoms and triples, query your own Core node.

Applies to V2 · @0xintuition/deployments 0.1.1 · @0xintuition/protocol 4.1.0