I am running a few tests using Jest and Polkadot.js, and I need to reset the state before each test. Should I do that or spawn a new node each time? And if so, what's the best way to do it? I am using the substrate node template.

Thank you.

2 Answers 2


You can use --dev on almost any node, each time you start/restart a node, this will get a random /tmp/substrateXXXX folder to contain all the DB and keys for the single session, so you don't need to worry about resetting the DB or anything like that.

Example assuming you are using the node template, as illustrated in the Create your first Substrate blockchain tutorial

# Starting in the working directory of the node template
cargo b -r
# Build takes a while...
# Once completed, run:
./target/release/node-template --dev
# Output looks like:
2021-11-24 15:36:35 Running in --dev mode, RPC CORS has been disabled.
2021-11-24 15:36:35 Substrate Node
2021-11-24 15:36:35 ✌️  version 4.0.0-dev-82b7c2c-aarch64-macos
2021-11-24 15:36:35 ❤️  by Substrate DevHub <https://github.com/substrate-developer-hub>, 2017-2021
2021-11-24 15:36:35 📋 Chain specification: Development
2021-11-24 15:36:35 🏷 Node name: six-wash-9274
2021-11-24 15:36:35 👤 Role: AUTHORITY
2021-11-24 15:36:35 💾 Database: RocksDb at /tmp/substrateP1jD7H/chains/dev/db
2021-11-24 15:36:35 ⛓  Native runtime: node-template-100 (node-template-1.tx1.au1)
2021-11-24 15:36:35 🔨 Initializing Genesis block/state (state: 0xa59b…5331, header-hash: 0xc5d2…37f3)
2021-11-24 15:36:35 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.
2021-11-24 15:36:35 ⏱  Loaded block-time = 6s from block 0xc5d2fdad35e14684753f087c1a20f022274e154d39add4f7efe34e95476a37f3
2021-11-24 15:36:35 Using default protocol ID "sup" because none is configured in the chain specs
2021-11-24 15:36:35 🏷 Local node identity is: 12D3KooWG5niQF5bjsFao3D8DZRpUUB6uWZC2pK8hCDZ94zsr8Sc
2021-11-24 15:36:35 📦 Highest known block at #0

Notice: /tmp/substrateP1jD7H/chains/dev/db is the DB directory, and each time you start with --dev, a random string will be used for the DB. You can restart using that same DB with the --base-path /tmp/substrateP1jD7H/ flag if you did for some reason want to restart a previous test DB, and override the --dev behavior to start a new one.

You can manually purge the DB only for a chain with the purge-chain subcommand on most nodes as well:

# Clear a specific base path specified chain
./target/release/node-template purge-chain --base-path /tmp/substrateP1jD7H/

# Clear 
./target/release/node-template purge-chain --local
  • Thank you Dan. And off topic, since you were kind and answered: I can't find if there is a way of running the node with a 0 block time, in order to test pallets without worrying about consensus delays. Do you know? Thank you. May 10, 2022 at 18:34
  • @JohnHilkinson Could you mark this reply as the answer? For your other questions, you could open a new question on StackExchange. Sep 6, 2022 at 13:20

You can run your node with --tmp. This will put the database into a temporary directory that is deleted when the node is closed. Thus, every time you will start again from genesis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.