Skip to content

Using Sudo to Impersonate Other Accounts

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. This allows you to perform privileged actions while managing your network, such as impersonating other accounts.

In this guide, you'll learn how to use Sudo to impersonate other accounts. For example, this guide will use the Sudo account to pose as an arbitrary account and transfer funds from said account.

Warning

The balance transfer demonstrated in this guide is dubious, and it is shown only as an example of using Sudo.

Checking Prerequisites

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

  • A Tanssi-powered network (Quick Trial or Dedicated)
  • Your network's Sudo account connected to your network's Polkadot.js Apps. You can refer to the Managing Sudo guide for instructions on injecting your Sudo account into Polkadot.js Apps

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

Locating your Sudo address on apps.tanssi.network

Warning

It's critical to protect your Sudo account key with the utmost security precautions, as it grants privileged access to your Tanssi network.

Using the Sudo As Method

As you know, the Sudo account can perform privileged functions, including impersonating other accounts. When submitting a call via sudoAs, the runtime will first authenticate the Sudo key and then dispatch the desired function call with the Signed origin from a given account. In the following example, the sudoAs method will orchestrate sending some tokens to another account. While the result is similar to using Sudo with a forceBalanceTransfer call, the following example uses a regular balance transfer call where the origin is the sender's account rather than the Sudo account.

To make a sudoAs call to impersonate another account, navigate to the Developer tab of Polkadot.js Apps for your Tanssi-powered network and click on Sudo. If you do not see Sudo in this menu, then you have not associated the Sudo account with Polkadot.js Apps. Ensure that your Sudo account is injected by your wallet and connected to Polkadot.js Apps. Then, take the following steps:

  1. Select the Sudo pallet
  2. Select the sudoAs method
  3. Select or paste in the desired account to impersonate
  4. Select the desired pallet for the call to submit. In this case, it is the balances pallet
  5. Select the transferAllowDeath method
  6. Specify the destination account for the balance transfer
  7. Specify the number of tokens to send
  8. Press SubmitSudo and confirm the resulting pop-up

Make a Sudo as call

The other account had a starting balance of 1,000 tokens before the call, and subsequently dropped to 995 as expected.

Check balances on Polkadot.js Apps

Using Sudo and the Dispatch As Utility

The following section will demonstrate using Sudo to dispatch calls from an arbitrary origin. When submitting a call in this manner, the runtime will first authenticate the Sudo key and then dispatch the call using the utility pallet and the dispatchAs function, allowing the transaction's origin to be exactly what you'd like.

To do so, navigate to the Developer tab of Polkadot.js Apps for your Tanssi-powered network and click on Sudo. If you do not see Sudo in this menu, you have not associated the Sudo account with Polkadot.js Apps. Ensure that your Sudo account is injected by your wallet and connected to Polkadot.js Apps. Then, take the following steps:

  1. Select the Sudo pallet
  2. Select the Sudo method
  3. Select the desired pallet for the call to submit. In this case, it is the utility pallet
  4. Select the dispatchAs method
  5. Select system from the dropdown
  6. Select the signed origin, which sets the origin of the transaction to be the specified account rather than root
  7. Select the desired pallet for the call to submit. In this case, it is the balances pallet
  8. Select the transferAllowDeath method
  9. Specify the destination account for the balance transfer
  10. Specify the number of tokens to send
  11. Press SubmitSudo and confirm the resulting pop-up

Use Sudo Dispatch As on Polkadot.js Apps

The other account had a starting balance of 995 tokens prior to the call and dropped to 990 as expected.

Check balances on Polkadot.js Apps

And that's it! The Developer Portal section has plenty more guides on how to manage your Tanssi network.

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: December 16, 2024
| Created: March 13, 2024