# PocketIC persistent state?

**URL:** <https://forum.dfinity.org/t/pocketic-persistent-state/45544>\
**Category:** Developers\
**Tags:** pocketic\
**Created:** [April 29, 2025, 8:24pm UTC](https://forum.dfinity.org/t/pocketic-persistent-state/45544 "2025-04-29T20:24:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![akup](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/akup/32/4381_2.png) [@akup](https://forum.dfinity.org/u/akup)\
**Post date:** [April 29, 2025, 8:24pm UTC](https://forum.dfinity.org/t/pocketic-persistent-state/45544/1 "2025-04-29T20:24:40Z")

</div>

Can PocketIC store deployed canisters, stable memory and network topology between restarts?

For example I’ve started PocketIC server and set up some network topology T, also I’ve deployed canister A and canister B, and filled the stable memory. Then I’ve stopped the PocketIC server.  
Is it possible to start it with already deployed canister A and B, and persisted stable memory (or even general memory) from the last run?

Where does PocketIC store it’s state? If a current versions of DFX uses PocketIC how DFX solves storing state between restarts?

I found nothing in a docs and on the forum

UPD:  
I’ve found with\_state and with\_state\_dir functions in client library sources: [ic/packages/pocket-ic/src/lib.rs at master · dfinity/ic · GitHub](https://github.com/dfinity/ic/blob/master/packages/pocket-ic/src/lib.rs#L233)

But there are absolutely no documentation. Can anybody explain how to use it?

---

<div class="post-metadata">

**Author:** ![ilbert](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ilbert/32/8717_2.png) [@ilbert](https://forum.dfinity.org/u/ilbert)\
**Post date:** [April 29, 2025, 11:04pm UTC](https://forum.dfinity.org/t/pocketic-persistent-state/45544/2 "2025-04-29T23:04:38Z")

</div>

When using the [PocketIC Rust library](https://crates.io/crates/pocket-ic), you can create a PocketIC instance with the [`with_state_dir`](https://docs.rs/pocket-ic/8.0.0/pocket_ic/struct.PocketIcBuilder.html#method.with_state_dir) method, as described in the [Persisting state of a PocketIC instance](https://github.com/dfinity/ic/blob/master/packages/pocket-ic/HOWTO.md#persisting-state-of-a-pocketic-instance).  
This way, you can specify the path you want PocketIC to persist the state to.

---

<div class="post-metadata">

**Author:** ![mraszyk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mraszyk/32/7945_2.png) [@mraszyk](https://forum.dfinity.org/u/mraszyk)\
**Post date:** [April 30, 2025, 5:34am UTC](https://forum.dfinity.org/t/pocketic-persistent-state/45544/3 "2025-04-30T05:34:48Z")

</div>

> [@akup](#):
>
> But there are absolutely no documentation.

There are [tutorials](https://github.com/dfinity/ic/blob/master/packages/pocket-ic/HOWTO.md) on how to use common features.

---

<div class="post-metadata">

**Author:** ![akup](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/akup/32/4381_2.png) [@akup](https://forum.dfinity.org/u/akup)\
**Post date:** [April 30, 2025, 10:31am UTC](https://forum.dfinity.org/t/pocketic-persistent-state/45544/4 "2025-04-30T10:31:20Z")

</div>

Thank you pointing the [Persisting state of a PocketIC instance](https://github.com/dfinity/ic/blob/master/packages/pocket-ic/HOWTO.md#persisting-state-of-a-pocketic-instance) chapter. Missed this chapter in tutorial.

Moreover it saves and restores topology when state\_dir is provided and uses it, but not from new instance create request parameters.
