Skip to content

Using Sudo to Manage Your ContainerChain

Introduction

Sudo is a module that enables privileged runtime calls to be dispatched when called from the Sudo account. Sudo is sometimes colloquially referred to as a superuser or god-like account. There can only be a single Sudo account at a time. However, the Sudo keys can be rotated to give Sudo privileges to a new account.

All Tanssi ContainerChains come with the Sudo pallet by default, and you're required to designate an account as the Sudo address when launching your ContainerChain. This enables you to perform privileged actions to manage your chain, such as upgrading your runtime or minting new native tokens. While the Sudo pallet is required to launch your ContainerChain on the TestNet, you can decommission the Sudo pallet and transition to decentralized governance after the MainNet launch.

In this guide, you'll learn how to use Sudo to upgrade your ContainerChain's runtime and perform other privileged actions like minting tokens.

Checking Prerequisites

For the examples in this guide, you will need to have the following:

  • A Tanssi ContainerChain (Snap or Dedicated)
  • Your ContainerChain's Sudo account connected to your ContainerChain's Polkadot.js Apps

If you're unsure what your ContainerChain's Sudo account is, you can find it in your Tanssi Dashboard underneath the Properties section.

Locating your Sudo address on apps.tanssi.network

Note

You should always protect your Sudo account key with the utmost security precautions, as it grants privileged access to your ContainerChain.

Configuring Polkadot.js Apps

After navigating to Polkadot.js Apps for your ContainerChain, you'll need to add your Sudo account. Injecting your Sudo account into Polkadot.js Apps from a browser extension is considered safer than storing accounts directly in the browser. However, you can still import your Sudo account directly into the browser's cache. This method does not require the use of any extensions. To import an account into Polkadot.js in this manner, take the following steps:

  1. Click on Settings
  2. Under in-browser account creation select Allow local in-browser account creation
  3. Press Save

Allowing creation of in-browser storage

Then, head back to the accounts tab and press Account. You'll then be able to replace the pre-generated private key with that of your sudo account.

Adding account on Polkadot.js Apps

Note

In-browser key storage is not suitable for production environments. This example is provided for demonstration purposes only in a TestNet environment.

Upgrading Your Runtime

To get started, head to Polkadot.js Apps for your ContainerChain. The Polkadot.js Apps link for your ContainerChain can be found in your Tanssi Dashboard underneath the Tooling section.

Locating your Polkadot.js Apps Link on apps.tanssi.network

Prior to the upgrade, you'll need to have the Wasm runtime ready to upload. You'll also need to have your Sudo account accessible in Polkadot.js Apps. Then, take the following steps:

  1. Navigate to the Developer Tab of Polkadot.js Apps for your ContainerChain
  2. Click on Sudo. If you do not see Sudo in this menu, then you have not associated the Sudo account with Polkadot.js Apps. Make sure that your Sudo account is injected by your wallet and connected to Polkadot.js Apps
  3. Select the system pallet
  4. Select setCode
  5. Toggle the fileUpload switch to enable uploading your Wasm runtime file
  6. Upload your Wasm runtime
  7. Press Submit Sudo and confirm the transaction in your wallet

Upgrading your Runtime on Polkadot.js Apps

You can verify that your runtime upgrade was successful by checking the runtime version in the upper left-hand corner. In this case, we can see that the ContainerChain's runtime was successfully upgraded to version 400.

Check Runtime version on Polkadot.js Apps

Minting Tokens

As you know, the Sudo account has the ability to perform privileged functions, including minting additional tokens. When setting up your ContainerChain on apps.tanssi.network, you can specify genesis account balances. In other words, you have the ability to endow accounts with initial balances upon launching your ContainerChain. However, you can also mint new tokens after launch with the help of the Sudo account.

Note

This tutorial demonstrates assigning arbitrary token balances on a TestNet ContainerChain that has no value. You should carefully consider the ramifications of creating additional tokens on your own ContainerChain.

Checking Existing Account Balance

The next section will demonstrate how to assign arbitrary token balances to accounts using the Sudo account. This process will overwrite the specified account's existing balance, so verifying the account is empty is a good practice before continuing. To check an account's balance, take the following steps:

  1. Navigate to the Developer tab of Polkadot.js Apps and click on Chain State
  2. Select the system pallet to query
  3. Select account
  4. Paste in the account address or select it from the dropdown
  5. Press + icon
  6. You'll see the balance information returned at the bottom, including free, reserved, and frozen balances

Check balances on Polkadot.js Apps

Assigning Balances with Sudo

To assign an account balance to an account, make sure to have your Sudo account accessible in Polkadot.js Apps. Then, take the following steps:

  1. Navigate to the Developer Tab of Polkadot.js Apps for your ContainerChain
  2. Click on Sudo. If you do not see Sudo in this menu, then you have not associated the Sudo account with Polkadot.js Apps. Make sure that your Sudo account is injected by your wallet and connected to Polkadot.js Apps
  3. Select the balances pallet
  4. Select the forceSetBalance method
  5. Paste in the account address to endow with tokens or select it from the dropdown
  6. Enter the amount of tokens to endow the account with. In this example, we specify 9000000000000000000 for nine native tokens. Remember that EVM ContainerChains have 18 decimals while Substrate or Custom ContainerChains decimals are configured when launching the chain. If you're unsure how many decimals your ContainerChain has, navigate to the Settings tab and Click on Metadata
  7. Press Submit Sudo and confirm the transaction in your wallet

Force assign balances on Polkadot.js Apps

Changing the Sudo Account

Changing your ContainerChain's Sudo account is a straightforward process. Also known as rotating your sudo keys, this process will remove sudo access from the existing sudo account and grant it to the new account. There can only be one sudo account at any time. However, you are free to change the sudo account as often as you would like.

Prior to getting started, make sure that you have your existing Sudo account accessible in Polkadot.js Apps. Then, take the following steps:

  1. Navigate to the Developer Tab of Polkadot.js Apps for your ContainerChain
  2. Click on Sudo. If you do not see Sudo in this menu, then you have not associated the Sudo account with Polkadot.js Apps. Make sure that your Sudo account is injected by your wallet and connected to Polkadot.js Apps
  3. Select the Set sudo key heading
  4. Select the new account you'll transfer sudo privileges to
  5. Press Reassign and confirm the transaction in your wallet

Change Sudo account on Polkadot.js Apps

Note

Ensure that you have access to the new sudo account. Once sudo is transferred, it cannot be undone without access to the current sudo key.

The information presented herein has been provided by third parties and is made available solely for general information purposes. Tanssi does not endorse any project listed and described on the Tanssi Doc Website (https://docs.tanssi.network/). Tanssi Foundation does not warrant the accuracy, completeness or usefulness of this information. Any reliance you place on such information is strictly at your own risk. Tanssi Foundation disclaims all liability and responsibility arising from any reliance placed on this information by you or by anyone who may be informed of any of its contents. All statements and/or opinions expressed in these materials are solely the responsibility of the person or entity providing those materials and do not necessarily represent the opinion of Tanssi Foundation. The information should not be construed as professional or financial advice of any kind. Advice from a suitably qualified professional should always be sought in relation to any particular matter or circumstance. The information herein may link to or integrate with other websites operated or content provided by third parties, and such other websites may link to this website. Tanssi Foundation has no control over any such other websites or their content and will have no liability arising out of or related to such websites or their content. The existence of any such link does not constitute an endorsement of such websites, the content of the websites, or the operators of the websites. These links are being provided to you only as a convenience and you release and hold Tanssi Foundation harmless from any and all liability arising from your use of this information or the information provided by any third-party website or service.
Last update: February 2, 2024
| Created: January 31, 2024