Module 2: Submitting Extrinsics

Building one block at a time

Learn to submit transactions, track their status, and handle errors effectively. Master the art of building reliable blockchain applications.

5 lessons3-4 hoursBeginner

Course Progress

0%

0 of 5 lessons completed

1

Setting Up a Keypair

20 min
Beginner
🔒

Complete previous lesson

🔒

Sending Balance Transfers

25 min
Beginner
🔒

Complete previous lesson

🔒

Tracking Transaction Status

30 min
Intermediate
🔒

Complete previous lesson

🔒

Events & Result Validation

25 min
Intermediate
🔒

Complete previous lesson

🔒

Error Handling

30 min
Intermediate

Setting Up a Keypair

Create account from mnemonic or inject via Polkadot{.js} extension

1

Theory

Keypair Management

To submit transactions, you need a keypair that can sign transactions. There are several ways to create and manage keypairs.

Keypair Types:

  • Mnemonic: 12 or 24-word seed phrase
  • Polkadot{.js} Extension: Browser extension for key management
  • Raw Seed: Direct private key (not recommended for production)

Code Example

import { Keyring } from '@polkadot/keyring';
import { mnemonicGenerate } from '@polkadot/util-crypto';

// Method 1: Generate new mnemonic
const mnemonic = mnemonicGenerate();
console.log('Generated mnemonic:', mnemonic);

// Method 2: Create keyring and add account
const keyring = new Keyring({ type: 'sr25519' });
const account = keyring.addFromMnemonic(mnemonic, { name: 'My Account' });
console.log('Account address:', account.address);

// Method 3: Add account with existing mnemonic
const existingMnemonic = 'your twelve word mnemonic here';
const existingAccount = keyring.addFromMnemonic(existingMnemonic, { name: 'Existing Account' });

// Method 4: Polkadot{.js} Extension (if available)
if (window.injectedWeb3) {
  const extension = await window.injectedWeb3['polkadot-js'].enable('Your App Name');
  const accounts = await extension.accounts.get();
  console.log('Extension accounts:', accounts);
}

Challenge

Keypair Setup

Create a keyring and add an account from mnemonic, then display the address

Validation: Successfully generate and display account address

Try It Yourself

Code Editor

JAVASCRIPT
Loading...
22 lines

Console Output

Run your code to see the output here...