Rust
Installation
Add the account_sdk
crate to your Cargo.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
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:
#[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("http://localhost:5050").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
"http://localhost:5050".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:
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:
controller.execute(vec![your_function_call()], None).await.unwrap();