SDK/Guides

Examples

PREVIEW

The SDK ships five examples and the MCP server two. They run on a local network in this order; each later one reads the state the first one writes.

FileWhat it shows
packages/sdk/examples/localnet.tsPublishes Essey immutably on a local network (the UpgradeCap is destroyed in the publish transaction, and the run stops if any UpgradeCap is left), and plays the owner's device: builds each owner action with the SDK as unsigned bytes and signs it with a separate owner key, the way a phone would. The agents never see that key. Sets up two lenders and one borrower.
packages/sdk/examples/lend.tsTwo lender agents post offers; an offer under the owner's mandate floor is refused on chain with treasury::ERateBelowFloor.
packages/sdk/examples/borrow-repay.tsA borrower agent tries an offer above its borrow rule (refused on chain, ERateAboveCeiling), then tries to send a loan's proceeds into a second cash treasury its rules do not name (refused on chain, ECashNotAllowed), then borrows from the cheapest offer and repays through the treasury desk; its SUI treasury ends where it started. It then tries to borrow from a second pool its rules do not pin (refused on chain, EPoolNotAllowed), and borrows and repays from the pinned pool. Last, it borrows until the allowance is short, is refused on chain (EOverAllowance), and borrows again after the owner re-sets the rules.
packages/sdk/examples/sealed-room.tsThe borrower's agent key is refused a room open (NOT_AGENT_CALL); the borrower's own wallet, a separate plain key, opens a sealed room from its own SUI, two lenders consent and bid sealed, the cheapest bid is settled and repaid. On localnet there are no Seal key servers, so the lenders place random bytes of the sealed length and the borrower ranks the lenders' own openings against the on-chain commitments; on testnet the same file encrypts and opens with Seal (not verified on testnet).
packages/sdk/examples/keys-together.tsOne key creates a treasury and keeps both caps. EsseyAgent.start refuses with KEYS_NOT_SEPARATE, and the MCP server exits before serving.
packages/mcp/examples/claude.tsPrints the Claude Code and Claude Desktop configuration for the local borrower, then drives the real MCP server with the official MCP client the way Claude does: list tools, read, borrow, repay, build an owner renewal, read warnings. See Run it with Claude.
packages/mcp/examples/upkeep.tsUpkeep on localnet: a lender's loan defaults and its upkeep loop hands the owner the collect bytes; the borrower's upkeep brings home what the default left; a loan inside the repay lead is repaid by the borrower's upkeep loop. Runs essey-sui-mcp upkeep --passes 1 with each agent's environment.

The MCP examples start essey-sui-mcp only when an agent key file is already there. The server requires that file before it starts, even to list its tools. It reads the path only from ESSEY_AGENT_KEY_FILE. That variable is required and has no default. From the project that installed the packages, this writes a mode-600 testnet file and prints the new address:

Shell
node --input-type=module -e "import { createAgentKeyFile } from '@esseyonsui/sui-sdk'; console.log(createAgentKeyFile('agent.env', 'testnet'))"

Point the server at it with ESSEY_AGENT_KEY_FILE=agent.env. essey-sui-init --key writes the same kind of file when that path is missing.

Run them#

Shell
scripts/sdk-e2e-local.sh

The script starts a fresh local network, runs the seven files in order, then re-reads every digest the run printed from the chain. It needs the sui binary.