-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
2,463 additions
and
1,648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Configuration | ||
|
||
Controller provides several configuration options related to chains, sessions, and theming. | ||
|
||
## ControllerOptions | ||
|
||
```typescript | ||
export type ControllerOptions = { | ||
policies?: Policy[]; | ||
rpc?: string; | ||
propagateSessionErrors?: boolean; | ||
theme?: string; | ||
colorMode?: ColorMode; | ||
}; | ||
``` | ||
|
||
- **policies** (`Policy[]`): An array of policies defining permissions for session keys. | ||
- **rpc** (`string`): The URL of the RPC for Slot deployments. | ||
- **theme** (`string`): The theme name for the wallet interface. See the [Theming](./theming.md) section for details on how to add and configure custom themes. | ||
- **propagateSessionErrors** (`boolean`): Whether to propagate transaction errors back to the caller. | ||
- **colorMode** (`"light"` \| `"dark"`): The color mode of the interface. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,162 @@ | ||
--- | ||
title: Using starknet-react | ||
title: starknet-react | ||
sidebar_position: 1 | ||
--- | ||
|
||
### Installation | ||
|
||
Install the necessary packages: | ||
|
||
```sh | ||
# Using npm | ||
npm install @cartridge/connector @cartridge/controller @starknet-react/core starknet | ||
|
||
# Using yarn | ||
yarn add @cartridge/connector @cartridge/controller @starknet-react/core starknet | ||
|
||
# Using pnpm | ||
pnpm add @cartridge/connector @cartridge/controller @starknet-react/core starknet | ||
``` | ||
|
||
### Setting Up the Connector | ||
|
||
Import the `ControllerConnector` and create an instance: | ||
|
||
```typescript | ||
import ControllerConnector from "@cartridge/connector"; | ||
|
||
const connector = new ControllerConnector(); | ||
``` | ||
|
||
```ts | ||
### Configuring the Connector | ||
|
||
You can customize the `ControllerConnector` by providing configuration options during instantiation. The `ControllerConnector` accepts an options object of type `ControllerOptions` that allows you to configure various settings such as policies, RPC URLs, theme, and more. | ||
|
||
Here's an example: | ||
|
||
```typescript | ||
import ControllerConnector from "@cartridge/connector"; | ||
const connector = new CartridgeConnector() | ||
import { Policy } from "@cartridge/controller"; | ||
|
||
// Define policies for sessions | ||
const policies: Policy[] = [ | ||
{ | ||
selector: { | ||
target: "0xYourContractAddress", | ||
function: "incrementCounter", | ||
}, | ||
description: "Allows incrementing the counter", | ||
}, | ||
]; | ||
|
||
// Create the connector with configuration options | ||
const connector = new ControllerConnector({ | ||
rpc: "https://your-custom-rpc-url", | ||
policies: policies, | ||
starterPackId: "your-starter-pack-id", | ||
theme: "default", | ||
colorMode: "dark", | ||
propagateSessionErrors: true, | ||
}); | ||
``` | ||
|
||
#### Customizing the Wallet Interface | ||
|
||
You can customize the appearance of the wallet interface by specifying `theme` and `colorMode`. | ||
|
||
Example: | ||
|
||
```typescript | ||
const connector = new ControllerConnector({ | ||
theme: "my-custom-theme", | ||
colorMode: "light", | ||
}); | ||
``` | ||
|
||
... | ||
<StarknetProvider autoConnect connectors={[connector]}> | ||
... | ||
</StarknetProvider> | ||
... | ||
### Integrating with `StarknetProvider` | ||
|
||
Wrap your application with the `StarknetProvider` and pass the connector: | ||
|
||
```typescript | ||
import { StarknetProvider } from "@starknet-react/core"; | ||
|
||
function App() { | ||
return ( | ||
<StarknetProvider autoConnect connectors={[connector]}> | ||
{/* Your components */} | ||
</StarknetProvider> | ||
); | ||
} | ||
``` | ||
|
||
### Connecting a Wallet | ||
|
||
Use the `useConnect` and `useAccount` hooks to manage wallet connections: | ||
|
||
```typescript | ||
import { useConnect, useAccount } from "@starknet-react/core"; | ||
function ConnectWallet() { | ||
const { connect, connectors } = useConnect(); | ||
const { address } = useAccount(); | ||
const controllerConnector = connectors[0]; | ||
return ( | ||
<div> | ||
{address ? ( | ||
<p>Connected: {address}</p> | ||
) : ( | ||
<button onClick={() => connect({ connector: controllerConnector })}> | ||
Connect Wallet | ||
</button> | ||
)} | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
### Performing Transactions | ||
|
||
Execute transactions using the `account` object: | ||
|
||
```typescript | ||
import { useAccount } from "@starknet-react/core"; | ||
function IncrementCounter() { | ||
const { account } = useAccount(); | ||
const onIncrement = async () => { | ||
await account.execute([ | ||
{ | ||
contractAddress: "0xYourContractAddress", | ||
entrypoint: "incrementCounter", | ||
calldata: ["0x1"], | ||
}, | ||
]); | ||
}; | ||
return <button onClick={onIncrement}>Increment Counter</button>; | ||
} | ||
``` | ||
|
||
## Session creation | ||
### Accessing Account Details | ||
|
||
Retrieve the connected account's address and username: | ||
|
||
```typescript | ||
import { useAccount } from "@starknet-react/core"; | ||
function AccountInfo() { | ||
const { account, address } = useAccount(); | ||
// Assuming the account object has a method to get the username | ||
const username = account ? account.username : null; | ||
```ts | ||
const connector = new CartridgeConnector([{ | ||
target: "0xdead", | ||
method: "have_turn", | ||
}]) | ||
return ( | ||
<div> | ||
<p>Account Address: {address}</p> | ||
{username && <p>Username: {username}</p>} | ||
</div> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: Overview | ||
sidebar_position: 0 | ||
--- | ||
|
||
![Cartridge Controller Overview](./img/controller.png) | ||
|
||
Cartridge Controller is a gaming-specific smart contract wallet designed to provide seamless player onboarding and game interactions while maintaining compatibility with other wallets that implement the plugin account architecture. | ||
|
||
## Key Features | ||
|
||
### Simple & Secure | ||
|
||
- Utilizes Passkeys and Starter Packs for effortless player onboarding | ||
- Provides self-custodial embedded wallets tailored for your game | ||
|
||
### Designed for Fun | ||
|
||
- Implements session keys, allowing players to focus on gameplay | ||
- Securely authorizes games to submit transactions on behalf of users | ||
- Leverages the Cartridge Paymaster to cover execution costs | ||
|
||
### Customizable | ||
|
||
- Adapts to your game's needs | ||
- Customize look and feel through themes | ||
- Dynamically render assets, quests, and player activity | ||
|
||
### Identity and Reputation | ||
|
||
- Offers a portable identity for players across games | ||
- Enables quest completion, achievement earning, and reputation accrual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Sessions and Policies | ||
|
||
Catridge Controller supports requesting preapproval for a set of `policies`. When a policy is preapproved, games can perform the interaction seamlessly without requesting approval from the player each time. Policys are requested during connection. Executing transactions follows the same pattern and controller will take care of requesting player approval only when necessary. | ||
|
||
#### Defining Policies | ||
|
||
Policies allow your application to define permissions that can be pre-approved by the user. This enables seamless interaction without requiring user approval for each transaction that matches a policy. | ||
|
||
```typescript | ||
const policies: Policy[] = [ | ||
{ | ||
selector: { | ||
target: "0xYourContractAddress", | ||
method: "incrementCounter", | ||
}, | ||
description: "Allows incrementing the counter", | ||
}, | ||
{ | ||
selector: { | ||
target: "0xAnotherContractAddress", | ||
method: "transferTokens", | ||
}, | ||
description: "Allows transferring tokens", | ||
}, | ||
]; | ||
``` | ||
|
||
```ts | ||
// Using the controller directly. | ||
const controller = new Controller(policies); | ||
|
||
// Using starknet-react connector | ||
const connector = new CartridgeConnector(policies) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Theming | ||
|
||
This guide provides a comprehensive overview of how to create and apply custom themes to the controller. | ||
|
||
## Creating a Theme | ||
|
||
To create a theme, teams should commit the theme to [`packages/keychain/public/whitelabel`](https://github.com/cartridge-gg/controller/tree/main/packages/keychain/public/whitelabel) with the icon and banner included. The theme should conform to the `ControllerTheme` type: | ||
|
||
```ts | ||
type ControllerTheme = { | ||
id: string; | ||
name: string; | ||
icon: string; | ||
cover: string; | ||
colors: { | ||
primary?: string; | ||
primaryForeground?: string; | ||
}; | ||
}; | ||
``` | ||
|
||
See an example here: <https://github.com/cartridge-gg/controller/pull/421/files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.