Skip to content

Commit

Permalink
Improve controller docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Oct 3, 2024
1 parent 3e8eb3d commit 9e024e5
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 447 deletions.
45 changes: 9 additions & 36 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
# Website
# Documentation

This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
Welcome to the documentation for the Cartridge Account SDK.

### Installation
## New Guides

```
$ pnpm i
```
- [Using the Controller in Rust](docs/controller/using_controller_rust.md)
- [Using the Controller in TypeScript](docs/controller/using_controller_typescript.md)
- [Sessions and Configuration](docs/controller/sessions_and_configuration.md)
- [Examples](docs/controller/examples.md)

### Local Development
## Contributing

```
$ pnpm book start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

### Build

```
$ pnpm book build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

### Deployment

Using SSH:

```
$ USE_SSH=true pnpm book deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> pnpm book deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
We welcome contributions! Please refer to the [contribution guidelines](CONTRIBUTING.md).
15 changes: 0 additions & 15 deletions docs/docs/controller/get-starknet.md

This file was deleted.

21 changes: 0 additions & 21 deletions docs/docs/controller/sessions.md

This file was deleted.

87 changes: 87 additions & 0 deletions docs/docs/examples/rust.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
* * *

title: Using Controller in Rust

## sidebar_position: 2

## Using Controller in Rust

### Installation

Add the `account_sdk` crate to your `Cargo.toml`:

```toml
[dependencies]
account_sdk = { git = "https://github.com/cartridge-gg/controller", package = "account_sdk" }
starknet = "0.10" # Make sure to use a compatible version
```

### Importing Necessary Modules

```rust
use account_sdk::{
controller::Controller,
signers::Signer,
};
use starknet::{
accounts::Account,
providers::Provider,
signers::SigningKey,
core::types::FieldElement,
};
```

### Setting Up the Controller

Initialize the controller with necessary parameters:

```rust
#[tokio::main]
async fn main() {
// Create a signer (replace with your own private key)
let owner = Signer::Starknet(SigningKey::from_secret_scalar(FieldElement::from_hex_be("0xYourPrivateKey").unwrap()));
// Initialize the provider (replace with your RPC URL)
let provider = Provider::try_from("https://api.cartridge.gg/x/starknet/sepolia").unwrap();
let chain_id = provider.chain_id().await.unwrap();

// Create a new Controller instance
let username = "testuser".to_string();
let controller = Controller::new(
"your_app_id".to_string(),
username.clone(),
FieldElement::from_hex_be("0xYourClassHash").unwrap(), // Class hash
"https://api.cartridge.gg/x/starknet/sepolia".parse().unwrap(), // RPC URL
owner.clone(),
FieldElement::from_hex_be("0xYourControllerAddress").unwrap(), // Controller address
chain_id,
);

// Deploy the controller
controller.deploy().await.unwrap();

// Interact with the controller
// For example, execute a transaction
let call = your_function_call(); // Define your function call
controller.execute(vec![call], None).await.unwrap();
}
```

### Performing Transactions

Define function calls and execute them:

```rust
fn your_function_call() -> starknet::core::types::FunctionCall {
starknet::core::types::FunctionCall {
contract_address: FieldElement::from_hex_be("0xYourContractAddress").unwrap(),
entry_point_selector: starknet::core::utils::get_selector_from_name("yourEntryPoint").unwrap(),
calldata: vec![FieldElement::from(123)], // Replace with your calldata
}
}
```

Execute the function call using the controller:

```rust
controller.execute(vec![your_function_call()], None).await.unwrap();
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Using starknet-react
sidebar_position: 2
slug: /controller/starknet-react
sidebar_position: 1
---


```sh
yarn add @cartridge/connector @cartridge/controller @starknet-react/core starknet
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Getting Started
sidebar_position: 0
slug: /controller/getting-started
slug: /getting-started
---

Cartridge Controller is a gaming specific smart contract wallet plugin that enables seamless player onboarding and game interactions while maintaining compatibility with other wallets that implement the plugin account architecture (e.g. Argent).
Expand All @@ -21,23 +21,6 @@ const account = controller.connect();
account.execute({ ... });
```

## Usage with `starknet-react`

```sh
pnpm add @cartridge/connector @cartridge/controller @starknet-react/core starknet
```

```ts
import ControllerConnector from "@cartridge/connector";
const connector = new CartridgeConnector()

...
<StarknetProvider autoConnect connectors={[connector]}>
...
</StarknetProvider>
...
```

## Preapproving interactions

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.
Expand Down
14 changes: 0 additions & 14 deletions docs/docs/quests/completing-a-quest.md

This file was deleted.

15 changes: 0 additions & 15 deletions docs/docs/quests/creating-a-quest.md

This file was deleted.

127 changes: 0 additions & 127 deletions docs/docs/quests/example.md

This file was deleted.

Loading

0 comments on commit 9e024e5

Please sign in to comment.