> For the complete documentation index, see [llms.txt](https://docs.gage.cash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gage.cash/developers/sdk-signing.md).

# Sign with gage-sdk

Sign with gage-sdk: run an action with a signer your code holds, sign each prepared step with any wallet, and set spend limits for an agent.

gage never holds a key and never signs. Every plan approves exact amounts only (`auto_roll` and `put_auto_roll` leave the two standing approvals, and their plans say so), and simulates each step before it is sent.

## run() with your signer

```ts
const listed = await gage.run({ action: "borrow", ...terms }, signer);
if (listed.status !== "done" || !listed.loan) return { quote: quote.summary, listed, funded: null, collected: null };
```

`run(action, signer)` acts for the signer's own wallet only (`WALLET_MISMATCH` for another). It plans once, then builds, simulates, sends and waits for each step in order. A refusal before any step throws an `ApiError`. Once planned, it answers with `status` (`done`, `nothing_to_do` or `stopped`), each transaction sent with its outcome (`succeeded`, `reverted` or `pending`), the steps never sent, the reason it stopped in fixed words, and `loan`: the loan a borrow, a loop, a roll, a put or an LP loan opened.

A signer is any object with `address` and `sendTransaction(tx)`:

* `privateKeySigner(key)` holds a raw key in memory and sends through the chain's public RPC, or `rpcUrl`.
* `viemSigner(walletClient)` wraps a viem wallet client that carries an account. Create the client with `chain: robinhoodMainnet`, which the SDK exports: a signer refuses another chain's transaction (`CHAIN_MISMATCH`).
* An ethers wallet fits in a few lines.

## Sign each step yourself

For a browser wallet, a custody API or a Safe: prepare, sign `next`, wait for it to be mined, prepare again.

```ts
const plan = await gage.prepare(input);
if (plan.status === "done" || !plan.next) return { status: "done" as const, sent, summary: plan.summary };
// Park and unpark answer every call at once, from one reading of the chain: send those together (examples/park.ts).
if (plan.calls) throw new Error("This action's calls go together: send plan.calls in order, without preparing again");
const hash = await wallet.sendTransaction(plan.next.transaction);
sent.push({ label: plan.next.label, hash });
const receipt = await wallet.waitForReceipt(hash);
if (receipt.status !== "success") return { status: "reverted" as const, sent, summary: plan.summary };
// The action itself went out: preparing again would plan it a second time.
if (plan.next.final && !plan.again) return { status: "done" as const, sent, summary: plan.summary };
```

`prepare` answers `status` (`approval_required`, `ready` or `done`), `next` (the unsigned transaction, simulated now, with a gas estimate), `then` (the steps after it), a `summary` in words and the figures (`view`). `again: true` says `next` is a step that comes first, such as a vault's settle, and the action itself is prepared again once it is mined. When `next` is the action itself (`final`), send it once: a second send would list, loop, roll, deposit or withdraw again. See [Prepare a transaction](https://docs.gage.cash/ai-agents/transactions.md).

## Spend limits for an agent

`run(action, signer, { limit })` and `gageTools(gage, { signer, limit })` take a spend limit: a function asked with each action's figures before anything is sent. It throws to refuse, and nothing is sent; or it holds the amount and is told at the end whether the action itself went out.

```ts
return (view) => {
const amount = counted(view, usdg);
if (amount === 0n) return { release: () => undefined };
if (amount > each) throw new ApiError("SPEND_LIMIT", "Over this agent's limit for one action", 403);
```

gage-mcp builds its limits on this: unless its owner sets them, at most 100 USDG a loan, loop or deposit, and 250 USDG of each in any 24 hours. See [Connect with MCP](https://docs.gage.cash/ai-agents/mcp.md). Whether an agent signs under limits is its wallet owner's choice; the wallet's balance is the limit that always holds.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gage.cash/developers/sdk-signing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
