MFS402 : Table of Contents

Chapter 1

Lesson 3

Foundational

The polkadot.js overview

Minimal Rust and Cargo setup

Quiz it to win it

Take the quiz

1 Questions
10 XP

Setting Up Developer Environments for Polkadot and Substrate


Welcome, trailblazers! By now, we’ve dipped our toes into what Polkadot is and even have a cool project idea with CertiDOT. But what’s a builder without their tools? Lesson 3 is all about gearing us up with the right development environment so we can craft dApps and blockchains like pros.

Why Setting Up Matters


Before jumping into the action, let’s talk about why setting up our environment properly is critical. A well-oiled setup not only saves time but also reduces frustration. With Polkadot and Substrate’s ecosystem being vast, a good foundation ensures smooth sailing later. Plus, the tools we set up today will stay with us throughout this journey.

Tool #1: polkadot.js – The Power Console


Polkadot.js is a suite of tools, not just a browser extension. It provides a robust interface to interact with the Polkadot ecosystem, including account management, network interactions, and even smart contract operations. We’ll focus on two key components: The Browser Extension and The Hosted App.

  • The Browser Extension: A lightweight and secure way to manage accounts and interact with nodes.
  • The Hosted App: A more comprehensive interface for exploring networks, sending transactions, and managing contracts.
  • The Browser Extension:

  • 1. Download and Install: Head to polkadot.js and grab the extension for your browser. Confirm installation, and the extension icon should appear.
  • 2. Managing Accounts: Open the extension and click on 'Add Account.' Name the account and securely store the mnemonic phrase.
  • 3. Connecting to Networks: Switch between mainnets, testnets, or local nodes by providing the endpoint.
  • The Hosted App:

  • 1. Navigate to Polkadot.js Apps for deeper tools.
  • 2. Interact with Networks: Use the dropdown to switch networks or connect to a custom endpoint.
  • 3. Explore Features: View blocks in 'Explorer' or manage accounts.
  • IPFS Version: The Polkadot.js app also offers an IPFS-hosted version. While may not be completely in sycn with the latest updates with the hosted version, the IPFS-hosted version is a correct step towards decentralized and significantly more censorship-resistant.

    The API: We will discuss the Polkadot.js API separately in later chapters when we dive deep into interacting with the Polkadot ecosystem from within our app.

    Tool #2: Rust and Cargo – Our Development Backbone


    Polkadot’s heart beats with Rust, a language famous for its safety and performance. Cargo is Rust’s package manager, helping us build and manage dependencies seamlessly. Note that, here, we outline bare minimum setup needed for Rust (the language) and Cargo (the build system and package manager for Rust). We assume a Unix-like system (e.g., Mac or Linux). For different operating systems (e.g., Windows), the steps might vary.

    Open your terminal and run the following command to install Rust. This script automates the installation process for Rust and its associated tools.

    Follow the interactive setup prompts in the terminal. More than often, the standard installation is enough.

    Verify the installation by running this.

  • Use Cargo to create a new Rust project
  • Navigate to the project directory and build it. Observe how Cargo compiles the project and generates a binary.
  • Execute the project to see the output. This executes the compiled code and displays the output (e.g., Hello, world!).
  • Setting Up a Local Node


    While we will start with smart contract and application development, it is a good idea to dip our toes into node development at the earliest. This is primarily because, we can then use that Blockchain node for quick experimentation, deploying our smart contracts later etc.

    To start on the boilerplate is fairly simple. We can start with the Substrate contract template.

    Tip: Note that we used the substrate-contracts-node — purposefully ready-made primed for smart contract development with the substrate node template. We will explain what all these mean later, but we start with getting things up.

    While we can build the node ourselves in our local system, it is easier (and much faster!) to just get the binary from the repo (https://github.com/paritytech/substrate-contracts-node/releases).

    A caveat of this is that if your OS (e.g., Mac) is set with strict security control, the OS may not allow you to run the binary directly. You may change your settings to run (understanding the full ramifications of it, of course), or build the node from scratch in your local system first.

    If possible, we recommend trying to build the node for fun — if nothing, it feels great to watch the terminal as it gets built (and frustrated if it fails!).

    To build the node, we can simply use cargo. It will take some time depending on how powerful your local system is. Also, depending on your local system, it may not be successful at the first (or second!) if certain packages (e.g, protobuf) is missing.

    Starting the Local Node: Starting the node is as simple as executing the binary (either extracted from the zip file of the release or the compiled binary).

    Connecting polkadot.js to Our Local Node


    Now comes the magic. We'll use polkadot.js to interact with the node we just spun up.

  • Open the polkadot.js hosted app in your browser. (https://polkadot.js.org/apps/#/explorer)
  • If your local node is running, it will automatically pick up the local node. If not, go to the settings and switch to the local node endpoint (default: ws://127.0.0.1:9944).
  • Navigate to the "Explorer" tab to view block details and transactions.
  • Use the "Accounts" tab to send tokens between accounts or query balances.
  • We can see the latest blocks, connect the Polkadot extension for self-managed accounts.

    Some Troubleshooting Tips


  • Rust Compilation Taking Ages? Use the --release flag to speed things up by enabling optimizations.
  • Node Crashing? Ensure no other service is using the same port (default is 9944). If needed, change the port in the node configuration file.
  • Can't Connect with polkadot.js? Double-check our endpoint URL and ensure the node is running. Restart the node if needed.
  • Recap and What’s Next


    Congratulations! We’ve just set up a powerhouse development environment. From polkadot.js to Rust, we’re ready to start tinkering with Polkadot’s ecosystem. In the next lesson, we’ll explore smart contracts with Ink! — a key building block for dApps.

    Quiz it to win it

    Complete this quiz successfully to proceed to the next lesson and win upto 10XP.

    Start quiz for this lesson

    Completing this quiz will get you

    +10 Experience Points

    +3% course progress