Steps

Initialize Canister Manager

```rust use scaledstorage::nodemanager::{ CanisterManager, CanisterManagerEvent, InitCanisterManagerParam, NodeInfo, WasmInitArgs, };

//Replace TYPE with your own data type static mut CANISTER_MANAGER: Option> = None;

[init]

fn init(){ unsafe { CANISTER_MANAGER = Some(CanisterManager::new(ic::id(), |size| size > 50)); //replace closure with your own custom "should scale up" logic. } }

```

Add CanisterManager house-keeping methods

```rust

[update]

fn initwasm(param: WasmInitArgs) -> bool { unsafe { CANISTERMANAGER .asmut() .unwrap() .lifecycleinit_wasm(param) } }

[heartbeat]

async fn heartbeat() { unsafe { CANISTERMANAGER .asmut() .unwrap() .lifecyleheartbeatnode() .await; } }

[update]

async fn handleevent(event: CanisterManagerEvent) { unsafe { CANISTERMANAGER .asmut() .unwrap() .lifecyclehandle_event(event) .await } }

[update]

async fn initcanistermanager(param: InitCanisterManagerParam) { unsafe { match param.args { Some(args) => CANISTERMANAGER .asmut() .unwrap() .lifecyleinitnode(Some(args.allnodes)), None => CANISTERMANAGER.asmut().unwrap().lifecyleinit_node(None), } .await } }

```

Update candid file

```text

type installargs = record { allnodes: vec text; };

type initcanistermanagerparam = record { args: opt installargs; };

type migrate_args = record { data: blob; };

type wasminitargs = record { position: nat8; wasm_chunk: blob; };

type canistermanagerevent = variant { NodeCreated: text; NodeDeleted: text; Migrate: migrate_args; };

service: { "initcanistermanager":(initcanistermanagerparam)-> (); "handleevent":(canistermanagerevent)->(); "initwasm":(wasminit_args)->(bool); }

```

Access your data

```rust unsafe { let canistermanager = &mut CANISTERMANAGER.as_mut().unwrap().canister;

 let result = canister_manager.with_upsert_data_mut(key, |data| {
     *data = value;
     data.clone()
 });

 //result returns either a NodeResult::NodeId or NodeResult::Result

 match result {
     NodeResult::NodeId(node_id) => {
         //do something with node_id perhaps return it to the client
         //or forward the current request to the node_id like below
         CanisterManager::forward_request(node_id, "method_name", args)
     }
     NodeResult::Result(result) => {
         //do something with result
     }
 }

} ```

### Once canister has been deployed, canister manager must be initialized with ss_uploader

bash cargo install ss_uploader