How can I delete a canister smart contract?

If you want to permanently delete a specific canister smart contract or all canisters for a specific project on the Internet Computer blockchain mainnet, you can do so by running the dfx canister delete command.

 

Deleting a canister removes the canister identifier, code, and state from the Internet Computer network. Before you can delete a canister, you must first stop the canister to clear any pending message requests or replies.

 

To delete all canisters for a project running on the local Internet Computer network:

 

  1. Open a new terminal and navigate to your project directory.

  2. Start the Internet Computer network, if necessary.

    In most cases, this step is only necessary if you are running the Internet Computer network locally.

    If you were deleting canisters on a remote network, you would include the --network command-line option to perform tasks on that network.

     

  3. Check the status of the project canisters running on the local Internet Computer network by running the following command:

    dfx canister status --all
  4. Stop all of the project canisters by running the following command:

    dfx canister stop --all
  5. Then delete all of the project canisters by running the following command:

    dfx canister delete --all

 

For more information on canisters, check out the Internet Computer Docs or the Internet Computer Wiki.

Updated