# @cartridge/controller

> Cartridge Controller

Latest version **0.14.2** (published 2026-09-08) · 0 weekly downloads

## Install

```sh
npm install @cartridge/controller
pnpm add @cartridge/controller
yarn add @cartridge/controller
bun add @cartridge/controller
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.14.2 |
| Published | 2026-09-08 |
| First published | 2022-09-20 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22 |
| Dependencies | 10 |
| Unpacked size | 3.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 80 |
| Maintainers | tarrencev, broody, c7e-steeb |

## Links

- npm: https://www.npmjs.com/package/@cartridge/controller
- Repository: https://github.com/cartridge-gg/controller
- Homepage: https://github.com/cartridge-gg/controller#readme
- Issues: https://github.com/cartridge-gg/controller/issues
- npm.io page: https://npm.io/package/@cartridge/controller

## Dependencies (10)

- [bs58](https://npm.io/package/bs58.md) ^6.0.0
- [mipd](https://npm.io/package/mipd.md) ^0.0.7
- [ethers](https://npm.io/package/ethers.md) ^6.13.5
- [starknet](https://npm.io/package/starknet.md) ^10.0.2
- [micro-sol-signer](https://npm.io/package/micro-sol-signer.md) ^0.5.0
- [@cartridge/penpal](https://npm.io/package/@cartridge/penpal.md) ^6.2.4
- [@starknet-io/types-js](https://npm.io/package/@starknet-io/types-js.md) 0.10.2
- [@wallet-standard/wallet](https://npm.io/package/@wallet-standard/wallet.md) ^1.1.0
- [@cartridge/controller-wasm](https://npm.io/package/@cartridge/controller-wasm.md) 0.10.3
- [@starknet-io/get-starknet-core](https://npm.io/package/@starknet-io/get-starknet-core.md) 5.0.0

## Recent versions

- 0.14.2 (latest) — 2026-09-08
- 0.13.11-alpha.2 (prerelease) — 2026-03-30
- 0.14.1 — 2026-09-04
- 0.14.0 — 2026-08-05
- 0.13.16 — 2026-07-21
- 0.13.15 — 2026-07-17
- 0.13.14 — 2026-07-16
- 0.13.13 — 2026-07-09
- 0.13.12 — 2026-04-16
- 0.13.11 — 2026-04-03
- 0.13.11-alpha.1 — 2026-03-26
- 0.13.10 — 2026-03-19
- 0.13.10-alpha.1 — 2026-02-25
- 0.13.9 — 2026-02-16
- 0.13.7 — 2026-02-12
- … 181 more at https://npm.io/package/@cartridge/controller/versions

## README

![Controller Cover Image](.github/cover.png)

# Controller

Controller is a gaming specific smart contract wallet that enables seamless
player onboarding and game interactions.

It supports transaction signing using Passkeys and Session Tokens.

## Project structure

The project consists of several packages in the `packages` directory:

- **[keychain](packages/keychain)** - Sandboxed iframe hosted at
  https://x.cartridge.gg/ that fills the same role as an injected wallet like
  MetaMask or Rabby: holds keys, signs transactions, and prompts user for
  approval. Also displays account state (balances, activities, achievements).
- **[controller](packages/controller)** - Main SDK implementing the account
  interfaces required by [starknet.js](https://github.com/0xs34n/starknet.js).
  Ships two provider modes:
  - **ControllerProvider** (web apps) - Full-featured web wallet communicating
    with an embedded keychain iframe. Supports sessions as well as
    per-transaction approval.
  - **SessionProvider** (native apps) - Creates ephemeral session keys with
    pre-configured policies so transactions can execute without per-call
    approval.
- **[connector](packages/connector)** - Registers configured providers through
  wallet-standard discovery, making them available to Starknet Start's
  `<StarknetConfig>`.

Integration examples live in `examples/` (Next.js, Svelte, Node.js).

## Starknet.js version support

Pick the Controller and connector line that matches the Starknet.js version your
application is on:

| `@cartridge/controller` / `@cartridge/connector` | Starknet.js |
| ------------------------------------------------ | ----------- |
| `0.13.x`                                         | v8          |
| `0.14.x`                                         | v10         |

Both packages are released together and share a version number, so keep them on
the same line, and keep your application's Starknet.js dependency on the
matching major. See the migration notes above before moving an existing
application from `0.13.x` to `0.14.x`.

## Requirements and Starknet.js v10 migration

Controller requires Node.js 22 or newer and depends on Starknet.js `^10.0.2`.
Applications upgrading from Controller 0.13.x should move their Starknet.js
dependency to the same range so both resolve to a single copy. Starknet.js v10
no longer exposes provider methods through account instances, so application
code should use `account.provider.getChainId()`,
`account.provider.callContract()`, and `account.provider.waitForTransaction()`.

The previous `@starknet-react/core` and `@starknet-react/chains` integration has
moved to `@starknet-start/react@1.0.8`, with `@starknet-start/chains@1.0.7`,
`@starknet-start/providers@1.0.7`, and `@starknet-start/explorers@1.0.7`.
Starknet Start requires React 19.

Controller's marketplace and achievement integrations use
`@cartridge/arcade@0.4.0`, whose published dependency graph is aligned on
Dojo.js 2 (`@dojoengine/core`, `@dojoengine/grpc`, and `@dojoengine/sdk` at
`2.0.0`). Together, this migration requires Node.js 22, React 19, and the
Starknet.js version described above. Applications should upgrade these
dependencies together rather than mixing the previous Arcade 0.3 or Dojo.js 1
packages with Controller 0.14.

`@starknet-start/providers@1.0.7` and `@starknet-start/query@1.0.7` still
resolve Starknet.js v9, so an application that installs them alongside
Controller ends up with two copies of Starknet.js. This workspace collapses them
with a package manager override, and applications should do the same until those
packages depend on v10:

```json
{
  "pnpm": { "overrides": { "starknet": "^10.0.2" } },
  "overrides": { "starknet": "^10.0.2" }
}
```

## Automatic reconnection

`@starknet-start/react@1.0.8` accepts an `autoConnect` prop on
`<StarknetConfig>`, but it is only declared in the types — the provider never
reads it, so a connected player is dropped on page reload. Until it is
implemented upstream, reconnect from your own app: remember the last connector
that was connected, reconnect to it on load, and forget it on disconnect.

Both React examples ship a small hook that does exactly that, intended to be
copied into your own app to replicate the `autoConnect` feature:

- [`examples/minimal/src/useAutoConnect.ts`](examples/minimal/src/useAutoConnect.ts)
- [`examples/next/src/hooks/autoConnect.ts`](examples/next/src/hooks/autoConnect.ts)

It exports an `AutoConnect` component that renders nothing, so it can be mounted
inside the provider where the hooks have access to the Starknet Start context:

```tsx
import { AutoConnect } from "./useAutoConnect";

<StarknetConfig chains={[mainnet]} provider={provider} explorer={voyager}>
  <AutoConnect />
  {children}
</StarknetConfig>;
```

## Custom Torii endpoint

Set `toriiUrl` when a game uses a Torii indexer that is not derived from its
Slot project name:

```ts
import Controller from "@cartridge/controller";

const controller = new Controller({
  slot: "my-game-mainnet",
  toriiUrl: "https://torii.example.com",
});
```

An explicit `toriiUrl` takes precedence over `slot`. When `toriiUrl` is omitted,
Controller retains the legacy Slot-derived endpoint at
`https://api.cartridge.gg/x/<slot>/torii`.

A custom Torii is required to display custom ERC-20 and ERC-721 tokens in the
Controller.

## Self-funded gas headroom

When a transaction is sponsored by the paymaster, the player pays no gas and
this option does nothing. When the player pays for gas themselves (a direct
`execute` with a fee estimate, or a session transaction that falls back to
self-funding because the paymaster is unavailable), Controller reserves extra
gas headroom so that estimate-to-execution drift does not run the transaction
out of resources.

Keychain estimates the transaction, then hands the estimated gas amounts to the
wallet core. The core multiplies each gas amount (L1, L2 and L1 data) by the
multiplier exactly once and uses the result as the transaction's resource-bound
`max_amount`. Gas prices are not multiplied. Starknet charges for gas actually
consumed, so the multiplier raises the worst-case fee cap and the balance the
player must hold to submit the transaction, not the fee they typically pay.

The default is `1.5`. Set `selfFundedGasMultiplier` to raise it, for example
when a game's transactions consume gas that varies with on-chain state between
estimation and execution:

```ts
import Controller from "@cartridge/controller";

const controller = new Controller({
  selfFundedGasMultiplier: 3,
});
```

The supported range is `1.5` to `10` inclusive. The constructor throws a
`RangeError` for values outside it. The value is forwarded to Keychain in both
the iframe and standalone flows, and Keychain falls back to the default if it
receives a value it cannot use, so an out-of-range value never causes
transactions to fail.

## Controller client notifications

The controller emits toast notifications for wallet activity (transactions,
network changes, achievements, etc.). To display them, mount
`<ControllerToaster />` once in your app and import its stylesheet — it is
self-contained, with no extra dependencies to install:

```tsx
import { ControllerToaster } from "@cartridge/controller/react";
import "@cartridge/controller/react/styles.css";

function App() {
  return (
    <>
      {/* your app */}
      <ControllerToaster />
    </>
  );
}
```

Toast types emitted: `error`, `success`, `network`, `transaction`,
`marketplace`, `achievement`, `user`, `setting`, `credits`.

Optional props:

- `position` — screen placement (default: `bottom-right`)
- `duration` — display time in ms (default: `5000`)
- `disabledTypes` — toast types to suppress
- `collapseTransactions` — minimal transaction toasts (icon only)

## Development

### Frontend

Install pnpm via corepack:

```sh
corepack enable pnpm
```

Install dependencies:

```sh
pnpm i
```

Run Controller with examples:

```sh
pnpm dev
```

This command builds all workspace dependencies first and start these servers:

- http://localhost:3002: Controller Example (Next.js)
- http://localhost:5174: Controller Example (Svelte)
- http://localhost:3001: Keychain
- http://localhost:3003: Profile

The simplest way to then develop with your cartridge account is to port it over
from the production keychain:

- Login to your account at https://x.cartridge.gg/login
- Open your console, dump your account with `window.cartridge.exportAccount()`
  and copy it
- Visting your local keychain at http://localhost:3001/
- Load your account into your local keychain

```js
window.cartridge.importAccount("EXPORTED ACCOUNT");
```

---
_Source: https://npm.io/package/@cartridge/controller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
