We’re going to make a crypto wallet that allows you to create accounts, recover accounts, send and receive crypto and view your transactions. Very similar to the popular crypto wallet Metamask but with a few extra features.
We’ll be creating the wallet in such a way that it can be used as a standalone web app or as a browser extension.
As an additional bonus, we’re going to be using ChatGPT to help us write our code. If you don’t have access to chatGPT you can use find the code on Github.
You can also follow along with this tutorial as a video, use the written tutorial (this page), view the source code on Github, live demo at wallet.atila.ca or view the browser extension in the Chrome webstore (link won’t work yet, it will viewable once approved).
There are 3 different ways to get set up with the initial repo. Using a cloud IDE (option 3) is the simplest option and allows you to do everything in your browser without having to install anything. But I’ve found that sometimes the browser code takes longer to run and compile compared to running the code in your local machine.
Option 1 and 2 also gives you more customizability but requires more setup.
git clone [<https://github.com/atilatech/aqua-wallet>](<https://github.com/atilatech/aqua-wallet>)
cd aqua-wallet
git checkout 4341eb6d23407845678c8774003cac92c1a9e1c8
git checkout -b create_wallet
yarn install
npx create-react-app aqua-wallet --template typescript
A cloud IDE allows you to develop your React project quickly without having to download or install anything and customize your local environment.
Stackblitz is typically faster. With Codesandbox you can navigate to https://github.com/atilatech/aqua-wallet/tree/4341eb6d23407845678c8774003cac92c1a9e1c8 and then add “box” to the end of github in the URL.
First we’re going to add a button that allows you to create an account. 3:20 in the video.
ChatGPT Prompt: create a react typescript component called AccountCreate that has button called Create Account, when the button is clicked, it calls a create account function
Very good but we want createAccount
to be defined inside AccountCreate
:
Now we can add that file to our project. If you are running the project locally: mkdir -p src/scenes/Account && touch src/scenes/Account/AccountCreate.tsx
import as React from 'react';
interface AccountCreateProps {
}
const AccountCreate: React.FC<AccountCreateProps> () => {
const createAccount = () => {
// Your code to create an account goes here
}
return (
<div>
<button onClick={createAccount}>Create Account</button>
</div>
);
};
export default AccountCreate;
ChatGPT Prompt: create a typescript function that generates a seed phrase, private key and address using the ethers library
.7:30 in video
We can then ask it to generate using a seedPhrase if it’s passed in: 9:05 in video.
ChatGPT made a mistake in the previous code. 11:05 in video
That function actually won’t work and generates the following error: Type 'Mnemonic' is not assignable to type 'string'
.
Let’s see if ChatGPT can fix it’s mistake if we simply copy-paste the error message we’ve received:
If you are running the project locally: you can install it with yarn add ethers
If you’re using the web IDE like Stackblitz or CodeSandbox you can just search for ethers and add it to the project
To understand how we created this account, let’s talk about how a new account is created and how the seed phrase is connected to the private key and address. 15:10 in video.
Here is an overview of how to go from a seed phrase to a private key, public key, and address in Ethereum:
Guess what. The previous section (and diagram!) was written by chatGPT. I used the following prompts:
can you explain how to go from seed phrase to private key to public key to address in ethereum
Source: @tomiwa1a twitter
Seeing a concept explained visually helps make it easier to understand. ChatGPT can’t draw diagrams but it can write scripts that can generate concepts. Thanks to Tony Hirst’s blog post, Generating (But not Previewing Diagrams) using ChatGPT for the idea. You can follow this Twitter thread of me live-tweeting the experience of getting the diagram to work. 18:10 in the video.
Update: It should have said Elliptic Curve Digital Signature Algorithm ECDSA not ECMDA (thank you Kavitha for pointing this out in the Youtube comments and the blog)
ChatGPT Prompt: usem mermaid.js to make a diagram of this processs
can you please add labels to the arrows in the diagram showing where PBKDF2, ECMDA and Keccak are being used
Protip: You can copy-paste the generated code inside html.onlineviewer.net to quickly preview the diagram and ask ChatGPT to add a button to download the image.
Here’s the finished product:
You might be able to try your mileage with other diagram libraries like d3.js but I ran into token limits when I did that, maybe someone can try again with d3.js or another diagram library and share their results with me (@tomiwa1a or tomiwa@atila.ca ).
There are some pretty interesting bugs I ran into during this process, for example, ChatGPT was originally using an outdated version of mermaid.js but the solution was to ask it to “use latest version”.
We can ask ChatGPT to refactor our code to add a button that will allow us to recover existing accounts. 24:45 in the video.
refactor this component to also include a recover account button
when this button is clicked the first time only, it shows an input that accepts a seed phrase
When enter is pressed on that input, it calls the generate account function with the seedPhrase passed in
<Paste code in AccountCreate.tsx>
Our app will be launched as a browser extension and web app so we want to keep the dependencies simple, so we will manually download the comipled Bootstrap 5 css and js files and put them into our public/
folder and reference those files in index.html
. 26:50 in video.
Ask ChatGPT to rewrite the AccountCreate
component with Bootstrap styles. This part was impressive because it knew to use btn-primary
for the Create Account button and btn-secondary
for the recover account.
To convert our wallet from a browser into a browser extension following the following steps. 30: 15 in the video.
manifest.json
yarn build
The rest of the code can be found by watching the video at 35:05 onwards and using the code at aqua-wallet@1.0.0.
In order to get the Transactions we’ll be using the Moralis API. 53:55 in the video. We’re using a 3rd party API because reading from the blockchain is hard. Anytime you start integrating 3rd party APIs you want to make sure you’re very thoughtful about how and why you are integrating them. Here’s the thought process I used:
Why use Moralis?
Use Moralis HTTP API
// To test that your extension is working, we can trigger a request account
// copy the following scripts into your browser console
// source: <https://gist.github.com/ademidun/29268d38592a84703812c7984f4863cd>
ethereum
.request({ method: 'eth_requestAccounts' })
.then((accounts)=>{
console.log({accounts});
})
.catch((error) => {
console.error({error})
});
// add a Proxy to listen to when all methods on window.ethereum is called
// ChatGPT prompt: how can i listen to all the function calls for a given object
// ChatGPT: *returned a working function but only with `apply:`. Had to also include `get:` for it to work
// Chat GPT prompt: the proxy doesn't get called, please fix
window.ethereum = new Proxy(window.ethereum, {
// Proxy handler that intercepts function calls and property accesses
apply: function(target, thisArg, args) {
// Log the function call
console.log(`apply: ${target.name} called with arguments:`, args);
// Call the original function
return Reflect.apply(target, thisArg, args);
},
get: function(target, prop) {
// Return a function if the property is a function
if (typeof target[prop] === "function") {
return function(...args) {
// Log the function call
console.log(`get: ${String(prop)} called with arguments:`, args);
// Call the original function
return target[prop](...args);
};
}
// Return the original property value
return target[prop];
},
});
[Atlas](https://atlas.atila.ca/) is an AI-powered search engine that can find anything on Youtube. Search “basketball” and it will take you to the exact point in the video where they talk about Lebron James and Michael Jordan, even thou...
We’re going to build a web application that allows you to send the like Ethereum cryptocurrency and Binance Coin (BNB) cryptocurrency to any address using Metamask. You can see what the finished product looks like here: https://bit.dev/a...
A simple tutorial that explains how to set up your Metamask wallet to Atila!