| description | title |
|---|---|
Get started with Cartridge Controller by learning how to install, initialize, and integrate it into your application with various frameworks. |
Controller Getting Started |
Controller implements a standard StarkNet account interface and can be seamlessly integrated into your application like any other wallet.
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!:::code-group
npm install @cartridge/controller starknetpnpm install @cartridge/controller starknetyarn add @cartridge/controller starknetbun add @cartridge/controller starknet:::
Here's a simple example of how to initialize and use the controller:
import Controller from "@cartridge/controller";
// Initialize the controller without policies
// This requires manual approval for each transaction
const controller = new Controller();
// Connect to get an account instance
const account = await controller.connect();
// Execute transactions - user will see approval dialog
const tx = await account.execute([
{
contractAddress: "0x...",
entrypoint: "my_function",
calldata: ["0x1", "0x2"],
}
]);Note: When no policies are provided, each transaction requires manual user approval through the Cartridge interface. This is suitable for simple applications or testing, but games typically benefit from using session policies for a smoother experience.
For games that need gasless transactions and session management:
import Controller from "@cartridge/controller";
const controller = new Controller({
policies: {
contracts: {
// Your game contract
"0x1234...": {
name: "My Game Contract",
methods: [
{
name: "move_player",
entrypoint: "move_player",
description: "Move player character",
},
{
name: "attack",
entrypoint: "attack",
description: "Attack enemy",
},
],
},
},
},
});import React from "react";
import { sepolia, mainnet } from "@starknet-react/chains";
import {
StarknetConfig,
jsonRpcProvider,
starkscan,
} from "@starknet-react/core";
import ControllerConnector from "@cartridge/connector/controller";
// Create the connector outside the component to avoid recreation on renders
const connector = new ControllerConnector();
// Configure the JSON RPC provider
const provider = jsonRpcProvider({
rpc: (chain) => {
switch (chain) {
case mainnet:
return { nodeUrl: "https://api.cartridge.gg/x/starknet/mainnet" };
case sepolia:
default:
return { nodeUrl: "https://api.cartridge.gg/x/starknet/sepolia" };
}
},
});
export function StarknetProvider({ children }: { children: React.ReactNode }) {
return (
<StarknetConfig
chains={[mainnet, sepolia]}
provider={provider}
connectors={[connector]}
explorer={starkscan}
>
{children}
</StarknetConfig>
);
}For more detailed examples of how to use Cartridge Controller in different environments, check out our integration guides:
-
- Integration with
starknet-react - Hooks and components
- State management
- Integration with
-
- Svelte stores and reactivity
- Component lifecycle
- Event handling
-
- Native integration
- Error handling
- Async operations
Each guide provides comprehensive examples and best practices for integrating Cartridge Controller in your preferred environment.
- Learn about Session Keys
- Set up Multiple Signers for backup authentication
- Customize your Controller
- Set up Usernames
- Configure Paymaster