Skip to content

Getting Started

Controller implements a standard StarkNet account interface and can be seamlessly integrated into your application like any other wallet.

Quick Start

The fastest way to get started is to install the controller package and connect to Cartridge:

import Controller from "@cartridge/controller";
 
const controller = new Controller({});
const account = await controller.connect();
 
// You're ready to execute transactions!

When connect() is called, users will see an improved controller creation interface with username autocomplete functionality. As users type their username, they'll see matching existing accounts with user profiles, making it easier to connect to existing controllers or choose unique usernames for new accounts.

Installation

npm install @cartridge/controller starknet

Basic Usage

Here's a simple example of how to initialize and use the controller:

Without session policies

import Controller from "@cartridge/controller";
 
// All transactions will require manual approval
const controller = new Controller();

With session policies

Pass session policies to the Controller constructor to enable gasless transactions and pre-approved transactions.

import Controller from "@cartridge/controller";
import { SessionPolicies } from "@cartridge/controller";
 
const policies: SessionPolicies = {
  contracts: {
    // Your game contract
    "0x1234...": {
      name: "My Game Contract",
      methods: [
        { name: "move_player", entrypoint: "move_player" },
        { name: "attack", entrypoint: "attack" },
      ],
    },
  },
};
 
// `move_player` and `attack` txs will not require approval
const controller = new Controller({ policies });

With custom configuration

The Controller ships with sensible defaults for chain RPCs, but you can override them if needed.

import { constants } from "starknet";
import Controller from "@cartridge/controller";
 
const controller = new Controller({
  // Optional chain configuration
  chains: [
    { rpcUrl: "https://api.cartridge.gg/x/starknet/sepolia" },
    { rpcUrl: "https://api.cartridge.gg/x/starknet/mainnet" },
  ],
  defaultChainId: constants.StarknetChainId.SN_MAIN,
});

Connectors

Connectors provide standardized integrations of Controller into various types of applications.

Controller Connector (Web Applications)

The ControllerConnector provides a standard way to integrate with frontend frameworks like starknet-react.

import React from "react";
 
import { constants } from "starknet";
import { sepolia, mainnet } from "@starknet-react/chains";
import { StarknetConfig, jsonRpcProvider, cartridge } from "@starknet-react/core";
 
import { SessionPolicies } from "@cartridge/controller";
import { ControllerConnector } from "@cartridge/connector";
 
const policies: SessionPolicies = {
  // Define session policies here
};
 
// Create the controller connector
const controller = new ControllerConnector({
  policies,
});
 
// Configure the JSON RPC provider
const provider = jsonRpcProvider({
  rpc: (chain) => {
    switch (chain) {
      case mainnet:
      default:
        return { nodeUrl: "https://api.cartridge.gg/x/starknet/mainnet" };
      case sepolia:
        return { nodeUrl: "https://api.cartridge.gg/x/starknet/sepolia" };
    }
  },
});
 
// Create the Starknet provider
export function StarknetProvider({ children }: { children: React.ReactNode }) {
  return (
    <StarknetConfig
      defaultChainId={mainnet.id}
      chains={[mainnet, sepolia]}
      provider={provider}
      connectors={[controller]}
      explorer={cartridge}
    >
      {children}
    </StarknetConfig>
  );
}

Wallet Standard Integration

By default, the Controller exposes the StarknetWindowObject interface. However, the ControllerConnector also supports the get-starknet wallet standard, enabling integration with libraries like starknet-react and solid.js.

You can use the ControllerConnector to cast Controller to the wallet-standard compatible WalletWithStarknetFeatures interface:

import { ControllerConnector } from "@cartridge/connector";
import type { WalletWithStarknetFeatures } from "@starknet-io/get-starknet-wallet-standard/features";
 
// Now compatible with any library that expects WalletWithStarknetFeatures
const controller: WalletWithStarknetFeatures = (new ControllerConnector()).asWalletStandard();

Session Connector (Native Applications)

The SessionConnector enables native applications to create local sessions linked to a user's existing Controller account.

import { constants } from "starknet";
 
import { SessionPolicies } from "@cartridge/controller";
import { SessionConnector } from "@cartridge/connector";
 
const policies: SessionPolicies = {
  // Define session policies here
 };
 
const sessionConnector = new SessionConnector({
  policies,
  rpc: "https://api.cartridge.gg/x/starknet/mainnet",
  chainId: constants.StarknetChainId.SN_MAIN,
  redirectUrl: typeof window !== "undefined" ? window.location.origin : "",
  // Optional: specify keychain URL for custom deployments
  keychainUrl: "https://x.cartridge.gg",
});

Compatibility Guide

The following common dependencies are compatible with the latest version of Cartridge Controller (v0.10.3):

  "@cartridge/arcade": "0.0.2"
  "@cartridge/connector": "0.10.3"
  "@cartridge/controller": "0.10.3"
  "@cartridge/presets": "0.5.4"
  "@dojoengine/core": "^1.7.0"
  "@dojoengine/predeployed-connector": "1.7.0-preview.3"
  "@dojoengine/sdk": "^1.7.2"
  "@dojoengine/torii-client": "1.7.0-preview.3"
  "@dojoengine/torii-wasm": "^1.7.2"
  "@dojoengine/utils": "1.7.0-preview.3"
  "@starknet-io/types-js": "^0.8.4"
  "@starknet-react/chains": "^5.0.1"
  "@starknet-react/core": "^5.0.1"
  "@tailwindcss/vite": "^4.1.4"
  "@types/node": "^22.13.1"
  "@types/react": "^19.1.0"
  "@types/react-dom": "^19.1.0"
  "bignumber.js": "^9.3.0"
  "lucide-react": "^0.523.0"
  "prettier": "^3.6.1"
  "prettier-plugin-tailwindcss": "^0.6.13"
  "react": "^19.1.0"
  "react-dom": "^19.1.0"
  "recharts": "^3.1.0"
  "sonner": "^2.0.5"
  "starknet": "^8.1.2"
  "starknetkit": "^v2.12.1"
  "tailwindcss": "^4.1.4"
  "typescript": "^5.8.3"
  "vite": "^6.3.3"
  "vite-plugin-wasm": "^3.4.1"
  "zustand": "^5.0.3"

Migration Notes for v0.10.0

StarkNet v8 Breaking Changes

If you're using WalletAccount directly in your application, you'll need to update the constructor call:

// Before (v0.9.x)
const account = new WalletAccount(provider, address, signer);
 
// After (v0.10.0)
const account = new WalletAccount({
  nodeUrl: provider,
  address: address,
  signer: signer
});

Ethereum Wallet Integration Changes

The MetaMask SDK has been removed in favor of the EIP-6963 standard. If your application relied on MetaMask SDK-specific features:

  • Wallet detection now uses EIP-6963 standard wallet detection
  • All Ethereum wallets are now handled through a shared base class
  • This change improves bundle size and wallet compatibility

Lodash Removal

The lodash dependency has been completely removed. If you were importing lodash utilities from this package, you'll need to replace them with custom utilities or install lodash separately in your application.

Development Workflow

If you're contributing to the Cartridge Controller or running the examples locally, you have two development modes available:

Local Development Mode

pnpm dev

This runs all services locally with local API endpoints, perfect for offline development and testing changes to the controller itself.

Production API Testing Mode

pnpm dev:live

This hybrid mode runs the keychain and examples locally while connecting to production APIs. The dev:live mode provides production RPC endpoints, Auth0, Stripe, and Turnkey configurations while keeping the keychain frame at localhost:3001 and your application at localhost:3002.

Examples

For more detailed examples of how to use Cartridge Controller in different environments, check out our integration guides:

  1. React

    • Integration with starknet-react
    • Hooks and components
    • State management
  2. Svelte

    • Svelte stores and reactivity
    • Component lifecycle
    • Event handling
  3. Rust

    • Native integration
    • Error handling
    • Async operations

Each guide provides comprehensive examples and best practices for integrating Cartridge Controller in your preferred environment.

Next Steps