Let's say I forgot first 2 words of the seed, how could I find an account with ether in it?

Let's say I forgot first 2 words of the seed. I want to write a program that brute-forces all possible bip-39 word combinations for the first 2 words, generate private/public keys, addresses, and go through first 10 addresses to check if there's ether stored in there, and in that case, get a notification. How could I achieve it? I guess I must download the whole Ethereum blockchain, what else?

• In your other question there is some code to generate an address from a mnemonic ethereum.stackexchange.com/questions/84854/…. You'll have to add code to generate the mnemonics.
– Ismael
Commented Jul 19, 2020 at 18:34
• You don't need to download the whole blockchain. Just make your calls to a public node, like Infura. Commented Jul 20, 2020 at 18:41
• But have to be careful with sending too many requests in a short period of time to a public node. You will most probably trigger their rate limit ;) Commented Jan 13, 2022 at 10:06

For those wondering how many combinations have to be tried in the worst case scenario:

``````f(N) = Binomial[2048-(N-2), 2] * 2
``````

with `2048` being the number of words in the wordlist and `N` being the number of words in your seed phrase. The factor `2` results from the two possible orders, in which the words can appear.

For a seed phrases with lengths of `12`, `18`, and `24` words, this would result in

``````f(12)= 4151406
f(18)= 4126992
f(24)= 4102650
``````

combinations, respectively.

(I cannot comment.)

• It seems a strange formula to me. If you forgot the first two words of a seed, combinations are not related to how long the rest of the seed is. You only need to test 4194304 (2048*2048) combinations. Commented Jul 24, 2020 at 1:02
• The formula assumes that each word from the list can be only picked once. If this is not the case, your formula is correct. Commented Jul 24, 2020 at 10:18
• Oh, I see. Thanks for the clarification. Commented Jul 24, 2020 at 10:32
• BIP-39 allows duplicates and seed phrases do have duplicates, roughly around 13% of the time. Commented Jul 25, 2020 at 14:52

Use ganache cli to create the first 10 accounts from mnemonic. This will last less than a second and then you stop and restart with another permutation. So you can write a simple script to create the seeds and find the according accounts with a simple grep.

``````\$ ganache-cli -h 0.0.0.0 --mnemonic "mimic dune forward party defy island absorb insane deputy obvious brother immense"
``````

Expected output:

``````Ganache CLI v6.9.1 (ganache-core: 2.10.2)

Available Accounts
==================
(0) 0xfe84Ab89b7Fc902Ff3CfD756403a8f085B1639Aa (100 ETH)
(1) 0x9DC64b2558b458A15C7f01c192D874Ef460f0A29 (100 ETH)
(2) 0x94F57ed7e9af03A10e8EB23CE1B3c7914a182b0f (100 ETH)
(3) 0x936188f2C3C8E8c95e425b6fe41c2ac9E701585e (100 ETH)
(4) 0x95f29431AEb52C0D5DbEEEC36010b8e2CA69CB3D (100 ETH)
(5) 0x19356cc2300833E690088a5a09A2044A3CC2A1E2 (100 ETH)
(6) 0x8861CdFa38838531275cE12F9e795C3b9fF29cBE (100 ETH)
(7) 0x0712e8e819712C3bfdb098CE51C87a4Ac0296fd8 (100 ETH)

Private Keys
==================
(0) 0x6b657c280147dd393162442cda5f55b8af7c59986237f4c602531d1e994d5a6d
(2) 0x50f58d79e0b89e2f4070721184eaa96fd5c3d096d4885969cf3fac70aaf522cd
(3) 0xfa30d0923973acd541d3dd3e9f8c2d253b7ecd52b316478f9dd24c88d7eff16d
(5) 0xe820b165e308ac2a2b32cc2fd4d694373b9910ce216ebeddcec10dbc2091c618
(6) 0x0402143af3ed84c7d05ce13b8601733a6e9c01d287f30e481f180bb38174aae7
(7) 0x5ca5f7763a6b5d49deca6620803ec47c4dd910380e8e9cf7780857b95318a1a3
(8) 0x6708567060a74fe47d7f9b9e7a5af1bc30ffbc641566c96f6413323591042a3c
(9) 0xf15dabfb20f3e891e7a9308bb3acb5498200b968ca4feebf8e2e9e561ee71778

HD Wallet
==================
Mnemonic:      mimic dune forward party defy island absorb insane deputy obvious brother immense
Base HD Path:  m/44'/60'/0'/0/{account_index}

Gas Price
==================
20000000000
Gas Limit
==================
6721975

Call Gas Limit
==================
9007199254740991

Listening on 0.0.0.0:8545
``````
• Even if this took half a second for each run (I doubt it), this would take you several weeks in the worst case to go through all the combinations. I suppose you could run this in parallel after splitting the combinations up, but this seems like a hugely inefficient way to accomplish the task. Commented Jul 25, 2020 at 14:56

You only need the first two words and the password if used (salt). Assuming you didn't use any salt your salt is the static value "mnemonic" that leaves you with 2048 * 2048 = ~ 4194304 possible options based on bip-0039 english dictionary.

You can use a tool like https://github.com/sc0tfree/mentalist to generate the permutation from the mnemonic dictionary or script it yourself.