Approve from a wallet key
Link your agent approves a new agent from a phone with a passkey. You can also do it with the SDK alone: the owner signs in with a plain Sui wallet key, claims the agent's setup code and signs the account into existence. No site, no passkey. The agent's key and the owner's key stay on their own machines; the service only ever sees signatures.
Two keys, two clients:
| Who | Client | Signs in at |
|---|---|---|
| The agent | EsseyService(api, agentKey) | /v1/agent/challenge, /v1/agent/session |
| The owner | EsseyOwner(api, ownerKey) | /v1/auth/challenge, /v1/auth/session |
The two sessions never open each other's routes. Keep the two keys apart: if the agent's own key ends up holding its OwnerCap, the agent refuses to sign (see Key separation).
1. The agent asks for a setup#
import { createAgentKeyFile, EsseyService, loadAgentKey } from "@esseyonsui/sui-sdk";
const api = "https://sui-agent-prototype-production.up.railway.app";
createAgentKeyFile("/path/to/agent.env", "testnet"); // mode 600; skip if the file exists
const agentKey = loadAgentKey("/path/to/agent.env", "testnet");
const service = new EsseyService(api, agentKey);
await service.signIn();
const { code } = await service.startSetup("lender"); // one claim, 15 minutesHand code and the agent's address (agentKey.toSuiAddress()) to the owner. A code is spent by the first owner who claims it, so pass it only to the owner.
2. The owner claims it#
import { EsseyOwner, loadAgentKey } from "@esseyonsui/sui-sdk";
const ownerKey = loadAgentKey("/path/to/owner.env", "testnet"); // same file format; or any @mysten/sui Signer
const owner = new EsseyOwner(api, ownerKey);
await owner.signIn(); // proof: "wallet"
const agent = await owner.claim({ code, agent: agentAddress, name: "my-lender", preset: "steady" });claim peeks first and spends the code only if it names agentAddress; a code for any other address is refused with SETUP_MISMATCH and stays unspent. peek(code) alone shows the address and side without spending it.
3. The owner creates the account#
const form = {
name: "my-lender", preset: "steady",
totalBudget: "4", minLoan: "1", maxLoan: "2",
minRateBps: 800, maxLtvBps: 3500, termsDays: [1],
expiresAtMs: Date.now() + 3 * 86_400_000,
};
console.log((await owner.preview(form)).sentence);
const { digest } = await owner.sign(agent.id, "create", { form, amount: "4" });sign asks the service to build the owner transaction, signs those exact bytes with the owner's key and sends the signature back. A claim-default that also calls the published Pyth package is accepted. One create opens the treasury, gives the agent its AgentCap, gives the owner the OwnerCap, writes the rules and, with amount, deposits that much USDC from the owner's wallet. The service pays the gas. The actions and their refusals are in Agent transactions.
A borrower (startSetup("borrower"), then the same claim) signs create with the borrower form and no amount: the collateral, the spare SUI and the USDC float are in the form, and create moves them from the owner's wallet in that one transaction.
const form = {
name: "my-borrower", preset: "taker", // taker, switcher or shopper; switcher needs a pool
collateral: "0.4", amount: "0.3", // SUI put up; USDC to borrow
maxRateBps: 6_000, repayBeforeHours: 0, cashFloat: "0.2",
expiresAtMs: Date.now() + 3 * 86_400_000,
};
const { digest } = await owner.sign(agent.id, "create", { form });collateral, amount and cashFloat are decimal strings (SUI, USDC, USDC); maxRateBps is 1 to 100,000; repayBeforeHours 0 (off) to 720; expiresAtMs at least 62 minutes away and within 30 days; autoTopUp, topUpSui and autoClaim are optional. The rules are in Agent transactions. preview takes the lender form only (POST /v1/mandate/preview); the borrower form has no SDK preview.
The preset decides where the desk borrows. A switcher's rules pin the deployment's pool, so borrowFromPool is for a switcher. A taker borrows from open offers (borrowFromOffer) and a shopper through its sealed room; their rules pin no pool. A desk borrows only from the pool its rules pin, so borrowFromPool from either aborts treasury::assert_pool 27 EPoolNotAllowed. The rules each preset writes are in Agent transactions.
4. The agent starts#
import { connect, deploymentOf, EsseyAgent } from "@esseyonsui/sui-sdk";
let setup = await service.setup(); // still "claimed", account null, right after claim
while (!setup || setup.state !== "ready") { // poll GET /v1/agent/setup
await new Promise((r) => setTimeout(r, 2_000));
setup = await service.setup();
}
const chain = await connect({ network: "testnet" });
const live = await EsseyAgent.start({ chain, deployment, signer: agentKey, account: setup!.account, gas: "coins" });EsseyAgent.start runs the key-separation check against the chain before it returns an agent that signs. Fund its gas before it signs: see below.
Fund the agent's gas#
The agent signs its own transactions, so something has to pay their gas. Three ways:
| Gas | Set with | What the agent needs |
|---|---|---|
| Coins | gas: "coins" (the MCP server's default, ESSEY_GAS=coins) | One SUI coin at its address holding at least 50,000,000 MIST (AGENT_GAS_BUDGET, one transaction's budget). Without one, a signing call throws NO_COINS before anything is sent. The public Sui testnet faucet credits the address balance, not a coin object, so a faucet-funded address holds no such coin until one is sent to it. A sale-room bid also needs its deposit. |
| Address balance | gas: "address-balance" (EsseyAgent's default when gas is unset) | SUI in its address balance, which the public Sui testnet faucet credits and 0x2::coin::send_funds sends to. Every SUI coin it holds stays free. |
| Sponsored | EsseyService.sponsored(client, tx, await service.selfRunConfig()) | Nothing: the operator pays. Lending calls only, at most selfRun.gasBudgetMax (50,000,000 MIST) a transaction, 20 a minute and 200 a day, once the account is ready and the keys are separate. See Self-run agents. |
From the owner's wallet, fundGas sends one new coin, so it covers coins mode in one step:
await owner.fundGas(chain, agentAddress, 500_000_000n); // 0.5 SUI; refuses under 50,000,000 MISTThe owner pays this transfer's gas from its own SUI.
Fund the treasury#
The agent lends from its treasury, never from its own address. The owner funds it over the API, with no site:
| When | Call | What moves |
|---|---|---|
| At setup | owner.sign(id, "create", { form, amount: "4" }) | amount USDC from the owner's wallet into the new treasury, in the same transaction as the account. |
| Later | owner.sign(id, "deposit", { amount: "5" }) | More USDC in. |
| Any time | owner.sign(id, "withdraw", { amount: "2" }) | USDC back to the owner; without amount, the whole balance. |
amount is a decimal string in USDC. The service pays the gas of each. A deposit beyond the budget limit is refused with OVER_BUDGET_CAP. A create whose amount the wallet does not hold is refused with WALLET_SHORT, which says how much it holds and needs. A deposit from a wallet short of the USDC is refused with 400 and a message that starts Insufficient balance of <coin type> for owner <address>. Required: <base units>, which the SDK throws as SERVICE_REFUSED. The same calls over HTTP are in Agent transactions.
Routes#
The same flow over HTTP is in Self-run agents.