Skip to content

Commit c311719

Browse files
docs: update controller documentation to reflect current interface (#41)
* docs: update controller documentation to reflect current interface - Improve getting started guide with Quick Start section and better examples - Update configuration documentation with current ControllerOptions interface - Enhance session documentation with clearer explanations of how sessions work - Fix consistency issues in session policy structure across examples - Update Starknet React integration to use current best practices - Add configuration examples with session policies for gaming use cases - Improve overview to better highlight current capabilities Co-authored-by: Tarrence van As <tarrencev@users.noreply.github.com> * fix: address PR review comments - Replace rpc parameter with chains parameter in ControllerOptions - Add Chain type definition with rpcUrl property - Update chainId description to specify hex encoding - Remove redirectUrl option from ControllerOptions - Simplify Controller and ControllerConnector instantiation examples - Remove rpc parameters from all code examples Co-authored-by: Tarrence van As <tarrencev@users.noreply.github.com> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
1 parent 0ed6445 commit c311719

File tree

6 files changed

+121
-55
lines changed

6 files changed

+121
-55
lines changed

src/pages/controller/configuration.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@ Controller provides several configuration options related to chains, sessions, a
1010
## ControllerOptions
1111

1212
```typescript
13-
export type ControllerOptions = {
14-
// Provider options
15-
chains: [
16-
{ rpcUrl: "https://api.cartridge.gg/x/starknet/sepolia" },
17-
{ rpcUrl: "https://api.cartridge.gg/x/starknet/mainnet" },
18-
],
19-
defaultChainId: constants.StarknetChainId.SN_SEPOLIA,
13+
export type Chain = {
14+
rpcUrl: string;
15+
};
2016

17+
export type ControllerOptions = {
18+
// Chain configuration
19+
chains?: Chain[]; // Custom RPC endpoints for slot katana instances
20+
chainId?: string; // hex encoded
21+
2122
// Session options
22-
policies?: SessionPolicies; // Session policies
23+
policies?: SessionPolicies; // Session policies for pre-approved transactions
2324
propagateSessionErrors?: boolean; // Propagate transaction errors back to caller
24-
25-
// Preset options
26-
preset?: string; // The preset name
25+
26+
// Customization options
27+
preset?: string; // Preset name for custom themes and verified policies
28+
slot?: string; // Slot project name for custom indexing
2729
};
2830
```
2931

3032
The configuration options are organized into several categories:
3133

32-
- **Provider Options**: Core RPC configuration
33-
- [**Session Options**](/controller/sessions.md): Session and transaction related settings
34-
- [**Preset Options**](/controller/presets.md): Configure a custom theme and verified session policies using Presets
34+
- **Chain Options**: Core network configuration and chain settings
35+
- [**Session Options**](/controller/sessions.md): Session policies and transaction-related settings
36+
- **Customization Options**: [Presets](/controller/presets.md) for themes and verified policies, [Slot](/controller/inventory.md) for custom indexing

src/pages/controller/examples/svelte.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ import { account, username } from "../stores/account";
3939
import { ETH_CONTRACT } from "../constants";
4040

4141
let controller = new Controller({
42-
policies: [
43-
{
44-
target: ETH_CONTRACT,
45-
method: "approve",
46-
description:
47-
"Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
42+
policies: {
43+
contracts: {
44+
[ETH_CONTRACT]: {
45+
methods: [
46+
{
47+
name: "approve",
48+
entrypoint: "approve",
49+
description: "Approve spending of tokens",
50+
},
51+
{
52+
name: "transfer",
53+
entrypoint: "transfer",
54+
description: "Transfer tokens",
55+
},
56+
],
57+
},
4858
},
49-
{
50-
target: ETH_CONTRACT,
51-
method: "transfer",
52-
},
53-
// ... other policies
54-
],
55-
rpc: "https://api.cartridge.gg/x/starknet/mainnet" // sepolia, mainnet, or slot
59+
},
5660
});
5761
```
5862

src/pages/controller/examples/telegram.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const RPC_URL = "https://api.cartridge.gg/x/starknet/mainnet";
2727
export const SESSION_POLICIES = {
2828
contracts: {
2929
"0x70fc96f845e393c732a468b6b6b54d876bd1a29e41a026e8b13579bf98eec8f": {
30+
name: "Beast Game Contract",
31+
description: "Contract for beast game interactions",
3032
methods: [
3133
{
3234
name: "attack",

src/pages/controller/getting-started.mdx

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ title: Controller Getting Started
88
Controller implements a standard StarkNet account interface and can be
99
seamlessly integrated into your application like any other wallet.
1010

11+
## Quick Start
12+
13+
The fastest way to get started is to install the controller package and connect to Cartridge:
14+
15+
```ts
16+
import Controller from "@cartridge/controller";
17+
18+
const controller = new Controller();
19+
const account = await controller.connect();
20+
21+
// You're ready to execute transactions!
22+
```
23+
1124
## Installation
1225

1326
:::code-group
@@ -37,51 +50,88 @@ Here's a simple example of how to initialize and use the controller:
3750
```ts
3851
import Controller from "@cartridge/controller";
3952

40-
// Initialize the controller
53+
// Initialize the controller with basic configuration
4154
const controller = new Controller();
4255

4356
// Connect to get an account instance
4457
const account = await controller.connect();
4558

4659
// Execute transactions
47-
const tx = await account.execute({
48-
contractAddress: "0x...",
49-
entrypoint: "my_function",
50-
calldata: ["0x1", "0x2"],
60+
const tx = await account.execute([
61+
{
62+
contractAddress: "0x...",
63+
entrypoint: "my_function",
64+
calldata: ["0x1", "0x2"],
65+
}
66+
]);
67+
```
68+
69+
## Configuration with Session Policies
70+
71+
For games that need gasless transactions and session management:
72+
73+
```ts
74+
import Controller from "@cartridge/controller";
75+
76+
const controller = new Controller({
77+
policies: {
78+
contracts: {
79+
// Your game contract
80+
"0x1234...": {
81+
name: "My Game Contract",
82+
methods: [
83+
{
84+
name: "move_player",
85+
entrypoint: "move_player",
86+
description: "Move player character",
87+
},
88+
{
89+
name: "attack",
90+
entrypoint: "attack",
91+
description: "Attack enemy",
92+
},
93+
],
94+
},
95+
},
96+
},
5197
});
5298
```
5399

54100
## Usage with Starknet React
55101

56102
```tsx
57-
import React, { useCallback } from "react";
58-
103+
import React from "react";
59104
import { sepolia, mainnet } from "@starknet-react/chains";
60105
import {
61106
StarknetConfig,
62-
publicProvider,
63-
argent,
64-
braavos,
65-
useInjectedConnectors,
66-
voyager,
67-
Connector,
68107
jsonRpcProvider,
69-
cartridgeProvider,
108+
starkscan,
70109
} from "@starknet-react/core";
71-
72-
import { ControllerConnector } from "@cartridge/connector";
73-
74-
const cartridgeConnector = new ControllerConnector({
75-
rpc: cartridgeProvider().nodeUrl,
110+
import ControllerConnector from "@cartridge/connector/controller";
111+
112+
// Create the connector outside the component to avoid recreation on renders
113+
const connector = new ControllerConnector();
114+
115+
// Configure the JSON RPC provider
116+
const provider = jsonRpcProvider({
117+
rpc: (chain) => {
118+
switch (chain) {
119+
case mainnet:
120+
return { nodeUrl: "https://api.cartridge.gg/x/starknet/mainnet" };
121+
case sepolia:
122+
default:
123+
return { nodeUrl: "https://api.cartridge.gg/x/starknet/sepolia" };
124+
}
125+
},
76126
});
77127

78128
export function StarknetProvider({ children }: { children: React.ReactNode }) {
79129
return (
80130
<StarknetConfig
81131
chains={[mainnet, sepolia]}
82-
provider={cartridgeProvider()}
83-
connectors={[cartridgeConnector as never as Connector]}
84-
explorer={voyager}
132+
provider={provider}
133+
connectors={[connector]}
134+
explorer={starkscan}
85135
>
86136
{children}
87137
</StarknetConfig>

src/pages/controller/overview.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ title: Controller Overview
77

88
### TL;DR: Cartridge Controller is:
99

10-
- A gaming-focused smart contract wallet
11-
- Makes Web3 gaming accessible and fun via Session Keys
12-
- Handles player onboarding and transaction management
13-
- Provides identity and customization features for games
14-
- Compatible with other wallets that implement the plugin account architecture
10+
- A gaming-focused smart contract wallet for Starknet
11+
- Makes Web3 gaming accessible and fun via Session Keys and gasless transactions
12+
- Handles seamless player onboarding with Passkey authentication
13+
- Provides identity, achievements, and customization features for games
14+
- Compatible with popular frameworks like Starknet React and can be integrated across platforms
1515

1616
![Cartridge Controller Overview](/controller.png)
1717

src/pages/controller/sessions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ description: Learn about Cartridge Controller's session-based authentication and
55

66
# Sessions and Policies
77

8-
Cartridge Controller supports session-based authorization and policy-based transaction approvals. When a policy is preapproved, games can perform interactions seamlessly without requesting approval from the player each time.
8+
Cartridge Controller supports session-based authorization and policy-based transaction approvals. When policies are pre-approved by the user, games can execute transactions seamlessly without requesting approval for each interaction, creating a smooth gaming experience.
9+
10+
## How Sessions Work
11+
12+
1. **Policy Definition**: Games define which contract methods they need to call
13+
2. **User Approval**: Users approve these policies once during initial connection
14+
3. **Session Creation**: Controller creates a session with approved transaction permissions
15+
4. **Gasless Execution**: Games can execute approved transactions without user prompts
16+
5. **Paymaster Integration**: Transactions can be sponsored through Cartridge Paymaster
917

1018
## Session Options
1119

0 commit comments

Comments
 (0)