Learn how web3 wallets work

By building one in Google Sheets

You've definitely heard of web3 wallets like MetaMask, Rainbow, Phantom and others.

But, how do they work under the hood? What is their core functionality? In this Inverted Project, we will learn the mental model behind web3 wallets by building a wallet in Google Sheets.

You can join our Discord (TODO) to join discussions about this project or ask questions along the way.

Why Google Sheets?

Because it's weird 😁. Google Sheets also doesn't have the boilerplate code that other setups like a React app do. So we can focus on the core functionality without worrying about the abstractions and boilerplate introduced by frameworks like React.

Here is the starter Google Sheet for this project.(TODO)\ You can make a copy of it and start filling in the blanks.

The main purpose of a wallet: key storage

This is the single most important function of a wallet. Let's implement the storage functionality of our wallet.

Go to the "accounts" (TODO change image) sheet of our Google Sheet.

We will store the private keys in a column. The address for each private key will be to the right of it.

Your first task is to implement the GetAddress function. Go to Extensions → Apps Script

There you will see the unimplemented GetAddress function. This is just a plain Javascript function.

Implement it and then you can write =GetAddress(B2) in cell C2 to get the address for the private key in cell B2.

Seed phrase

Old wallets (back in the beginning of the cryptocurrency history) used to store private keys just like we did above.

But modern wallets work differently. They actually store a single "seed" phrase, from which multiple private keys can be derived. These private keys are actually interconnected. One seed can generate lots of private keys. Really lots of. The number has 50 digits. You're not going to run out:)

I suggest you read this article to get yourself familiar with the seed phrase:

If you're interested in the origins of the seed phrase and history of improvement to web3 wallets over time, you can read this:

If you're already familiar with the seed phrase, then read on.

Generating a seed phrase

A seed phrase is derived from the master private key. A master private key is just a random 128-bit number. This is how the seed phrase is derived from the master private key (image from 12 words that replaced your username and password):

Your task is to generate a random 128-bit master private key and derive the seed phrase from it. Fill in 2 functions: generateMasterPrivateKey and deriveSeedPhrase.

Next we will derive the our private keys from the seed phrase.

Deriving private keys from the seed

In progress...