Skip to content

Commit bcb7b50

Browse files
committed
formatting
1 parent f68f7b8 commit bcb7b50

File tree

3 files changed

+88
-89
lines changed

3 files changed

+88
-89
lines changed

.chain-interactions/accounts/create-account.md

Lines changed: 83 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ categories: Basics, Accounts, Developer Tools
1010

1111
Creating accounts is a fundamental operation when building applications on Polkadot and its parachains. Accounts serve as the basis for identity, asset ownership, and transaction signing. Understanding how to generate and manage accounts programmatically enables you to build wallets, automate operations, and create seamless user experiences.
1212

13+
Polkadot accounts are based on the SR25519 signature scheme by default, though ED25519 and ECDSA are also supported. Each account consists of a public key (address) and a private key (seed/mnemonic). **Keep your private keys secure and never share them**.
14+
1315
This tutorial will guide you through creating accounts using different programming languages and libraries.
1416

1517
## Prerequisites
@@ -20,138 +22,135 @@ Before starting, make sure you have:
2022
- Development environment set up for your chosen language
2123
- Familiarity with the programming language you'll be using
2224

23-
!!! note
24-
Polkadot accounts are based on the SR25519 signature scheme by default, though ED25519 and ECDSA are also supported. Each account consists of a public key (address) and a private key (seed/mnemonic). Keep your private keys secure and never share them.
25+
## Use JavaScript/TypeScript
2526

26-
## JavaScript/TypeScript
27+
JavaScript/TypeScript developers can use the Polkadot.js API to create and manage Polkadot accounts.
2728

28-
Create a new project directory and initialize it:
29+
1. Create a new project directory and initialize it:
2930

30-
```bash
31-
mkdir account-creator
32-
cd account-creator
33-
npm init -y && npm pkg set type=module
34-
```
31+
```bash
32+
mkdir account-creator
33+
cd account-creator
34+
npm init -y && npm pkg set type=module
35+
```
3536

36-
Install the required packages:
37+
2. Install the required packages:
3738

38-
```bash
39-
npm install @polkadot/util-crypto @polkadot/keyring
40-
npm install --save-dev typescript tsx
41-
```
39+
```bash
40+
npm install @polkadot/util-crypto @polkadot/keyring
41+
npm install --save-dev typescript tsx
42+
```
4243

43-
Create a file named `create-account.ts`:
44+
3. Create a file named `create-account.ts` and add the following code to it:
4445

45-
```typescript title="create-account.ts"
46-
--8<-- 'code/chain-interactions/accounts/create-account/create-account.ts'
47-
```
46+
```typescript title="create-account.ts"
47+
--8<-- 'code/chain-interactions/accounts/create-account/create-account.ts'
48+
```
4849

49-
Key aspects of the code:
50+
Key aspects of the code:
5051

51-
- **Mnemonic generation**: Uses `mnemonicGenerate()` to create a 12-word BIP39 mnemonic phrase for human-readable key backup
52-
- **Keyring**: The `Keyring` class manages accounts with specified signature scheme and address format
53-
- **SS58 format**: Setting `ss58Format: 0` configures addresses for the Polkadot relay chain
52+
- **Mnemonic generation**: Uses `mnemonicGenerate()` to create a 12-word BIP39 mnemonic phrase for human-readable key backup.
53+
- **Keyring**: The `Keyring` class manages accounts with a specified signature scheme and address format.
54+
- **SS58 format**: Setting `ss58Format: 0` configures addresses for the Polkadot relay chain.
5455
55-
Execute the script using `tsx`:
56+
4. Execute the script using `tsx`:
5657
57-
```bash
58-
npx tsx create-account.ts
59-
```
58+
```bash
59+
npx tsx create-account.ts
60+
```
6061

61-
You should see output similar to:
62+
You should see output similar to:
6263

63-
--8<-- 'code/chain-interactions/accounts/create-account/create-account-ts.html'
64+
--8<-- 'code/chain-interactions/accounts/create-account/create-account-ts.html'
6465

6566
## Python
6667

6768
Python developers can use the `substrate-interface` library to create and manage Polkadot accounts.
6869

69-
Create a new project directory and set up a virtual environment:
70+
1. Create a new project directory and set up a virtual environment:
7071

71-
```bash
72-
mkdir account-creator-python
73-
cd account-creator-python
74-
python3 -m venv venv
75-
source venv/bin/activate # On Windows: venv\Scripts\activate
76-
```
72+
```bash
73+
mkdir account-creator-python
74+
cd account-creator-python
75+
python3 -m venv venv
76+
source venv/bin/activate # On Windows: venv\Scripts\activate
77+
```
7778

78-
Install the required package:
79+
2. Install the required package:
7980

80-
```bash
81-
pip install substrate-interface
82-
```
81+
```bash
82+
pip install substrate-interface
83+
```
8384

84-
Create a file named `create_account.py`:
85+
3. Create a file named `create_account.py`:
8586

86-
```python title="create_account.py"
87-
--8<-- 'code/chain-interactions/accounts/create-account/create_account.py'
88-
```
87+
```python title="create_account.py"
88+
--8<-- 'code/chain-interactions/accounts/create-account/create_account.py'
89+
```
8990

90-
Key aspects of the code:
91+
Key aspects of the code:
9192

92-
- **Mnemonic generation**: The `generate_mnemonic()` function creates a BIP39-compatible phrase
93-
- **Keypair creation**: `Keypair.create_from_mnemonic()` derives keys from the mnemonic
93+
- **Mnemonic generation**: The `generate_mnemonic()` function creates a BIP39-compatible phrase.
94+
- **Keypair creation**: `Keypair.create_from_mnemonic()` derives keys from the mnemonic.
9495
95-
Execute the script:
96+
4. Execute the script:
9697
97-
```bash
98-
python create_account.py
99-
```
98+
```bash
99+
python create_account.py
100+
```
100101

101-
You should see output similar to:
102+
You should see output similar to:
102103

103-
--8<-- 'code/chain-interactions/accounts/create-account/create-account-py.html'
104+
--8<-- 'code/chain-interactions/accounts/create-account/create-account-py.html'
104105

105106
## Rust
106107

107108
Rust provides low-level access to Substrate primitives for account creation through the `sp-core` and `sp-keyring` crates.
108109

109-
Create a new Rust project:
110+
1. Create a new Rust project:
110111

111-
```bash
112-
cargo new account-creator-rust
113-
cd account-creator-rust
114-
```
112+
```bash
113+
cargo new account-creator-rust
114+
cd account-creator-rust
115+
```
115116

116-
Add dependencies to your `Cargo.toml`:
117+
2. Add dependencies to your `Cargo.toml`:
117118

118-
```toml title="Cargo.toml"
119-
[package]
120-
name = "account-creator-rust"
121-
version = "0.1.0"
122-
edition = "2021"
119+
```toml title="Cargo.toml"
120+
[package]
121+
name = "account-creator-rust"
122+
version = "0.1.0"
123+
edition = "2021"
123124
124-
[dependencies]
125-
sp-core = "28.0"
126-
sp-runtime = "31.0"
127-
```
125+
[dependencies]
126+
sp-core = "28.0"
127+
sp-runtime = "31.0"
128+
```
128129

129-
Create your account generation code in `src/main.rs`:
130+
3. Create your account generation code in `src/main.rs`:
130131

131-
```rust title="src/main.rs"
132-
--8<-- 'code/chain-interactions/accounts/create-account/create-account.rs'
133-
```
132+
```rust title="src/main.rs"
133+
--8<-- 'code/chain-interactions/accounts/create-account/create-account.rs'
134+
```
134135

135-
Key aspects of the code:
136+
Key aspects of the code:
136137

137-
- **Keypair generation**: [`sr25519::Pair::generate_with_phrase()`](https://docs.rs/sp-core/latest/sp_core/crypto/trait.Pair.html#method.generate_with_phrase){target=\_blank} creates a new key pair with mnemonic
138-
- **Public key extraction**: The [`public()`](https://docs.rs/sp-core/latest/sp_core/crypto/trait.Pair.html#tymethod.public){target=\_blank} method retrieves the public key from the pair
139-
- **SS58 encoding**: Uses Polkadot's address format for the human-readable address
138+
- **Keypair generation**: [`sr25519::Pair::generate_with_phrase()`](https://docs.rs/sp-core/latest/sp_core/crypto/trait.Pair.html#method.generate_with_phrase){target=\_blank} creates a new key pair with mnemonic.
139+
- **Public key extraction**: The [`public()`](https://docs.rs/sp-core/latest/sp_core/crypto/trait.Pair.html#tymethod.public){target=\_blank} method retrieves the public key from the pair.
140+
- **SS58 encoding**: Uses Polkadot's address format for the human-readable address.
140141
141-
Build and run the project:
142+
4. Build and run the project:
142143
143-
```bash
144-
cargo run
145-
```
144+
```bash
145+
cargo run
146+
```
146147
147-
You should see output similar to:
148+
You should see output similar to:
148149
149-
--8<-- 'code/chain-interactions/accounts/create-account/create-account-rs.html'
150+
--8<-- 'code/chain-interactions/accounts/create-account/create-account-rs.html'
150151
151152
## Where to Go Next
152153
153-
Now that you can create accounts programmatically, explore related guides to fund accounts and send transactions.
154-
155154
<div class="grid cards" markdown>
156155
157156
- <span class="badge guide">Guide</span> __Send Transactions with SDKs__
@@ -174,7 +173,7 @@ Now that you can create accounts programmatically, explore related guides to fun
174173
175174
---
176175
177-
Explore different methods for querying blockchain data including account balances and other chain state.
176+
Explore different methods for querying blockchain data, including account balances and other chain state.
178177
179178
[:octicons-arrow-right-24: Get Started](/chain-interactions/query-data/query-sdks/)
180179
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { cryptoWaitReady, mnemonicGenerate } from "@polkadot/util-crypto";
2-
import { Keyring } from "@polkadot/keyring";
1+
import { cryptoWaitReady, mnemonicGenerate } from '@polkadot/util-crypto';
2+
import { Keyring } from '@polkadot/keyring';
33

44
async function main() {
55
await cryptoWaitReady();
66

77
const mnemonic = mnemonicGenerate(12);
8-
const keyring = new Keyring({ type: "sr25519", ss58Format: 0 });
8+
const keyring = new Keyring({ type: 'sr25519', ss58Format: 0 });
99
const pair = keyring.addFromMnemonic(mnemonic);
1010

1111
console.log(`Address: ${pair.address}`);
1212
console.log(`Mnemonic: ${mnemonic}`);
1313
}
1414

15-
main().catch(console.error);
15+
main().catch(console.error);

.snippets/code/chain-interactions/accounts/create-account/create_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
keypair = Keypair.create_from_mnemonic(mnemonic)
55

66
print(f"Address: {keypair.ss58_address}")
7-
print(f"Mnemonic: {mnemonic}")
7+
print(f"Mnemonic: {mnemonic}")

0 commit comments

Comments
 (0)