Sub topic 1
Keys and wallets: what actually controls your funds
Prerequisites
This chapter assumes you know the following:
- A blockchain is a shared ledger that many computers keep in sync, and a cryptocurrency is a unit of value recorded on such a ledger.
- You can install and use a web or mobile app.
- For the optional code, you can read basic JavaScript.
You do not need to know any cryptography. The chapter explains the parts you need.
The core idea: control means holding a key
A bank account is controlled by the bank. You prove who you are, and the bank decides whether to move money. A blockchain has no such gatekeeper. The network accepts a transfer only if it carries a valid digital signature, and only the holder of the matching private key can produce that signature.
Your funds are never "inside" your wallet app. The ledger records balances for addresses. The wallet is software or hardware that holds your keys and signs transactions for you. Whoever holds the key can spend the funds. Whoever loses the key loses access, and nobody can reset it.
This is the single most important fact in the tutorial, and later chapters build on it.
Private key, public key and address
Three values are linked in one direction.
- The private key is a very large random number. It is the secret.
- The public key is calculated from the private key using elliptic-curve math. Anyone can see it.
- The address is a shorter value derived from the public key. It is what you give people so they can pay you.
On Ethereum-style networks, the private key is 256 bits, usually written as 64 hexadecimal characters. The public key is derived using the secp256k1 curve. The address is the last 20 bytes of the Keccak-256 hash of the public key, shown as 40 hexadecimal characters after a 0x prefix.
Each step is one-way. You can go from private key to public key to address, but you cannot work backwards. Guessing a private key is not feasible, because there are about 2^256 possibilities.
What a signature proves
When you send funds, the wallet builds a transaction and signs it with the private key. The network checks the signature against the public key. The check confirms two things: the sender holds the key, and the transaction was not altered after signing. The private key itself is never sent.
An address is not a secret. Publishing it lets people pay you and lets anyone view its balance and history. It does not let them spend.
Seed phrases and hierarchical wallets
Holding one key per address would be tedious to back up. Most wallets use a seed phrase (also called a recovery phrase or mnemonic), usually 12 or 24 words from a standard list defined in BIP-39.
The phrase encodes a master secret. From it, the wallet derives a whole tree of private keys using a method called a hierarchical deterministic (HD) wallet, defined in BIP-32 and BIP-44. A derivation path names a position in that tree. A common Ethereum path is m/44'/60'/0'/0/0, where the final number selects the account index.
This gives you several properties:
- One backup restores every account derived from the phrase.
- The same phrase and path always yield the same keys, on any compatible wallet.
- Adding accounts needs no new backup.
Types of wallets
Wallets differ in where the key lives and who controls it.
| Type | Where the key lives | Who controls it | Main trade-off |
|---|---|---|---|
| Software wallet (browser extension or mobile app) | Encrypted on your device | You | Convenient, but exposed if the device is compromised |
| Hardware wallet | Inside a dedicated secure chip | You | Signs offline, so malware cannot read the key, but costs money and can be lost |
| Custodial account (exchange) | On the provider's servers | The provider | Easy recovery, but you hold a claim on the provider, not the keys |
| Smart-contract wallet | Rules enforced by a contract | You, under programmable rules | Supports recovery and limits, but depends on contract code and network support |
A phrase often used is "not your keys, not your coins". With a custodial account, the provider's records say you are owed funds, and the provider holds the real keys. If the provider fails or freezes your account, you depend on its policies. With a self-custody wallet, you carry the full responsibility instead.
Hot and cold
A hot wallet is connected to the internet while its keys are available to sign. A cold wallet keeps keys on a device that never exposes them to a networked machine. A hardware wallet shows the transaction on its own screen, and you approve it with a button on the device. Check the amount and recipient on that screen, because the computer attached to it could be showing false details.
Generating a key in code
The following example creates a random wallet with ethers v6 and shows the three linked values. Use it to see the relationships, and never use a key generated or printed in a demo for real funds.
import { Wallet, HDNodeWallet } from "ethers";
// A random single key
const single = Wallet.createRandom();
console.log("Address:", single.address);
console.log("Public key:", single.publicKey);
console.log("Seed phrase:", single.mnemonic.phrase);
// Derive the same wallet again from the phrase and a path
const restored = HDNodeWallet.fromPhrase(
single.mnemonic.phrase,
undefined,
"m/44'/60'/0'/0/0"
);
console.log("Same address:", restored.address === single.address);The second part shows determinism. The phrase and path reproduce the same address, which is why a written backup is enough to recover.
Later chapters use the environment variable PRIVATE_KEY for sending examples. Keep such a key out of source code and version control, and use a throwaway key on a test network while learning.
Common errors and gotchas
- Storing the phrase digitally. Screenshots, cloud notes and emailed copies are exposed to anyone who breaches those services. Write it on paper or metal, and keep copies in separate secure places.
- Confusing the password with the key. A wallet app's password usually only encrypts the key on one device. If the device is lost, the password cannot restore anything. Only the seed phrase can.
- Assuming a wallet is tied to one network. The same key and address often work on many Ethereum-compatible networks. This is convenient, but it also means a leaked key exposes funds on all of them. The next chapters cover addresses and networks.
- Sharing the wrong thing. Share the address. Never share the private key or the phrase. A "public key" in some tools is not the same as an address, so check what a form asks for.
- Trusting recovery that does not exist. No chain operator can reverse a signed transaction or restore a lost key. Mistakes are permanent, as the chapter on irreversible transfers explains.
- Passphrase surprises. Some wallets support an optional extra word called a passphrase, sometimes called a "25th word". It produces a completely different set of accounts. If you forget it, the funds in those accounts are unreachable, even with the correct phrase.
- Entropy failures. Keys must come from a secure random source. Home-made generators, brain wallets and "vanity" tools from unknown sources have repeatedly led to stolen funds.
Checking your understanding
Exercise
A friend asks for your wallet's address so they can pay you, and a second person asks for your seed phrase "to verify your account". Which request is safe, and why?
Show answer
Only the address request is safe. An address is derived one way from the public key and lets others send you funds but not spend them. The seed phrase regenerates every private key in the wallet, so sharing it gives the recipient full control of all your accounts.
Exercise
You lose your phone, which had a software wallet with a password. You have a handwritten 12-word phrase and you set no passphrase. Can you recover your funds, and what do you do?
Show answer
Yes. The funds are recorded on the blockchain, and the phrase regenerates the keys. Install a compatible wallet on a new device, choose to import by recovery phrase, enter the 12 words, and use the same derivation path (usually the default). Check that the expected address appears. The old password is not needed.
Exercise
A coworker says a custodial exchange account and a self-custody wallet are "the same thing, just different apps". What is the key difference?
Show answer
In self-custody you hold the private keys, so you alone can sign transactions and you alone carry the backup responsibility. In a custodial account the provider holds the keys and you hold a claim recorded in its own database, so it can limit, freeze or lose access to your funds.