Skip to main content
This simple command-line tool allows you to clean up the state of a NEAR account without deleting it.

How it works

This JavaScript CLI tool deploys a state-cleanup.wasm contract replacing the current one, and then uses the new contract to clean up the account’s state, so you can easily redeploy a new contract or use the account in any other way. Here’s a quick snippet of the contract’s main code:
Check the GitHub repository and learn more about the State Cleanup tool.

How to use

Requirements

You’ll need NEAR CLI. You can install it by running:

Clear your account state

To clear your account state, follow these steps.
1

Login with NEAR CLI

This will store a full access key locally on your machine. Select the account you wish to clear the state.
Be sure to select Store the access key in my legacy keychain (compatible with the old near CLI) to store the access key on the legacy keychain.
2

Clone the near-clear-state repository

3

Install dependencies

4

Clear your state

If you want to clean the state of a mainnet account, use the --network option:
5

(Optional) Check your results

View all state keys that have been erased in your account:

Troubleshooting

If your contract state is large, depending on the RPC node, you may get the error:
This is an RPC issue, as the RPC node has a limited contract state view. You can prevent this error when calling view-state via the JSON RPC API by selecting an alternative RPC provider. You can find different providers in the RPC providers list. For example, you could replace the default RPC node in commands/clearState.js with another RPC server: