陳信仲 Garrick H.C. Chen
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Cryptocurrencies wallet development ## The test is still working on ..., the completion is about 50%. ## Test Goals To create a cryptocurrencies wallet for React practice and understanding Ethers library usage. ## Dev and Test Environment | OS | VS Code | Node.js | ether.js | react | axios | | -------- | -------- | -------- | -------- | -------- | -------- | | Ubuntu 22.04 | 1.76.2 | 18.15.0 | 6.2.0 | 18.2.0 | 1.3.5 | ## Table of contents: * Getting Started * Create Account Function * Ethers Library (Seed Phrase, Private Key, Public Key and Address) * Account Recovery * Getting Transactions * Multisig (working on...) * References ### Getting Started First of all, create a vite project on VS Code ``` npm create vite@latest wallet-dev-01 ``` ![](https://i.imgur.com/VN2zuev.png) ![](https://i.imgur.com/R2WZvVT.png) The **wallet_dev** is the parent folder of the main project called **wallet-dev-01** ![](https://i.imgur.com/9RO49pi.png) ### Create Account Function The page needs a button for creating an account, so ask ChatGPT : >please create react component called CreateAccount that has a button called Create Account, when the button is clicked, it call a createAccount function which is in the component ![](https://i.imgur.com/s5WSH3r.png) ![](https://i.imgur.com/Gc9nSWh.png) Make a folder in src called **scenes** and a folder **Account** in the scenes folder. According to the informations from ChatGPT create a file **src/scenes/Account/CreateAccount.jsx** ``` import React from 'react'; function CreateAccount() { function createAccount() { // Your create account logic here console.log('Create account clicked!'); } return ( <div> <button onClick={createAccount}>Create Account</button> </div> ); } export default CreateAccount; ``` and update the **src/App.jsx** ``` import React from 'react' import './App.css' import CreateAccount from './scenes/Account/CreateAccount'; function App() { return ( <div className="App"> <head>Wallet Dev 01</head> <CreateAccount /> </div> ) } export default App ``` ### Ethers Library (Seed Phrase, Private Key, Public Key and Address) Ask ChatGPT: >Please create a react function that generate seed phrase, private key, public key and address using the ethers library. ![](https://i.imgur.com/D7ry587.png) ![](https://i.imgur.com/O4LDPxu.png) Create jsx file **src/utils/AccountUtils.jsx** ``` import React, { useState } from "react"; import { ethers } from "ethers"; function EthAddressGenerator() { const [seedPhrase, setSeedPhrase] = useState(""); const [privateKey, setPrivateKey] = useState(""); const [publicKey, setPublicKey] = useState(""); const [address, setAddress] = useState(""); const generateAddress = () => { // Generate a new random wallet const wallet = ethers.Wallet.createRandom(); // Set the values in the state setSeedPhrase(wallet.mnemonic.phrase); setPrivateKey(wallet.privateKey); setPublicKey(wallet.publicKey); setAddress(wallet.address); }; return ( <div> <button onClick={generateAddress}>Generate Address</button> <p>Seed Phrase: {seedPhrase}</p> <p>Private Key: {privateKey}</p> <p>Public Key: {publicKey}</p> <p>Address: {address}</p> </div> ); } export default EthAddressGenerator; ``` And update the **src/App.jsx** ``` import React from 'react' import './App.css' import CreateAccount from './scenes/Account/CreateAccount'; import AccountUtils from './utils/AccountUtils'; function App() { return ( <div className="App"> <CreateAccount /> <AccountUtils /> </div> ) } export default App ``` Run the command `npm run dev` and press the button **Generate Address**, then we got the seed phrase, private key, public key and address ![](https://i.imgur.com/QJ5iFMP.png) According to the data on **Aqua Wallet Github** and **Ethers Library V6** the codes have been updated as follows **src/utils/AccountUtils.jsx** ``` import React, { useState } from "react"; import { Wallet } from "ethers"; export function EthAddressGenerator() { // const [seedPhrase, setSeedPhrase] = useState(""); // const [privateKey, setPrivateKey] = useState(""); // const [publicKey, setPublicKey] = useState(""); // const [address, setAddress] = useState(""); // const generateAddress = () => { // Generate a new random wallet const wallet = Wallet.createRandom(); // Set the values in the state // setSeedPhrase(wallet.mnemonic.phrase); // setPrivateKey(wallet.privateKey); // setPublicKey(wallet.publicKey); // setAddress(wallet.address); // }; const account = {"address": wallet.address, "privateKey": wallet.privateKey} const seedPhrase = wallet.mnemonic.phrase; console.log("return account: ", account) return {account, seedPhrase}; // return ( // <div> // <button onClick={generateAddress}>Generate Address</button> // <p>Seed Phrase: {seedPhrase}</p> // <p>Private Key: {privateKey}</p> // <p>Public Key: {publicKey}</p> // <p>Address: {address}</p> // </div> // ); } export async function RecoverAccount(seedPhrase, index) { const wallet = (seedPhrase.includes(" ")) ? Wallet.fromPhrase(seedPhrase, `m/44'/60'/0'/0/${index}`) : new Wallet(seedPhrase); const account = {"address": wallet.address, "privateKey": wallet.privateKey} console.log("return account: ", account) return {account, seedPhrase}; } ``` **src/scenes/Account/CreateAccount.jsx** ``` import React, { useState, useCallback } from 'react'; import { EthAddressGenerator, RecoverAccount } from '../../utils/AccountUtils' const recoveryPhraseKeyName = 'recoveryPhrase'; function CreateAccount() { // Declare a new state variable, which we'll call "seedphrase" const [seedphrase, setSeedphrase] = useState(''); // Declare a new state variable, which we'll call "account" const [account, setAccount] = useState(null); // Declare a new state variable, which we'll call "showRecoverInput" // and initialize it to false const [showRecoverInput, setShowRecoverInput] = useState(false); function createAccount() { // Your create account logic here console.log('Create account clicked!'); const result = EthAddressGenerator(); console.log(result.account) console.log(result.seedPhrase) setAccount(result.account) setSeedphrase(result.seedPhrase) } function handleChange(event) { // Update the seedphrase state with the value from the text input setSeedphrase(event.target.value); } const handleKeyDown = async (event) => { if (event.keyCode === 13) { event.preventDefault(); recoverAccount(seedphrase); } } const recoverAccount = useCallback( // recoverAccount could be used without recoveryPhrase as an arguement but then we would have to // put it in a deps array. async (recoveryPhrase) => { // Call the RecoverAccount function with no arguments // Call the RecoverAccount function and pass it 0 and the current seedphrase const result = await RecoverAccount(recoveryPhrase); // Update the account state with the newly recovered account setAccount(result.account); if (localStorage.getItem(recoveryPhraseKeyName) !== recoveryPhrase) { localStorage.setItem(recoveryPhraseKeyName, recoveryPhrase); } }, [] ); return ( <div> <form onSubmit={event => event.preventDefault()}> <button type="button" className="btn btn-primary" onClick={createAccount}> Create Account </button> {/* Add a button to toggle showing the recover account input and button */} {/* If show recover input is visible, clicking the button again will submit the phrase in the input */} <button type="button" className="btn btn-outline-primary ml-3" onClick={() => showRecoverInput ? recoverAccount(seedphrase) : setShowRecoverInput(true)} // if the recoveryinput is showing but there is no seedphrase, disable the ability to recover account disabled={showRecoverInput && !seedphrase} > Recover account </button> {/* Show the recover account input and button if showRecoverInput is true */} {showRecoverInput && ( <div className="form-group mt-3"> <input type="text" placeholder='Seedphrase or private key for recovery' className="form-control" value={seedphrase} onChange={handleChange} onKeyDown={handleKeyDown} /> </div> )} </form> <p>Address: {account === null? "": account.address}</p> <p>Address: {seedphrase === null? "": seedphrase}</p> </div> ); } export default CreateAccount; ``` **src/App.jsx** ``` import React from 'react' import './App.css' import CreateAccount from './scenes/Account/CreateAccount'; function App() { return ( <div className="App"> <CreateAccount /> </div> ) } export default App ``` The result of rapid testing Creating Account ![](https://i.imgur.com/3c586he.png) ### Account Recovery Recovering Account by seed phrase, the ethers library function is **Wallet.fromMnemonic** in **V5** and **Wallet.fromPhrase** in **V6.2.2** ![](https://i.imgur.com/N1pHy1D.png) Hiding the seedphrase ![](https://i.imgur.com/NLa548O.png) Just psate seedphrase and press enter for Recovering the account, the seedphrase doesn't show itself. Deposit coin on Sepolia testnet Wallet Address : 0x977b8CcFf21132896bb420eD15bB47b2178a0906 ![](https://i.imgur.com/t2gNOki.png) ### Getting Transactions Adding Provider and Transactions and the state stored in localstorage and apply a Moralis API key for requesting the transactions The ether.js V6 is changed a lot. ``` V5 const provider = new ethers.providers.JsonRpcProvider(goerli.rpcUrl); V6 const provider = new ethers.JsonRpcProvider(sepolia.rpcUrl); V5 ethers.utils.formatEther(accountBalance) V6 ethers.formatEther(accountBalance) ``` ![](https://i.imgur.com/oqkSz1V.png) The Balance is 0 ETH on `0x7984Ebb42AbD280FA31A4144357adD5EB3A16884` ![](https://i.imgur.com/Qs11KX3.png) Transfering ETH from `0x977b8CcFf21132896bb420eD15bB47b2178a0906` to `0x7984Ebb42AbD280FA31A4144357adD5EB3A16884` ![](https://i.imgur.com/pQGWnK0.png) Transfer completed ![](https://i.imgur.com/IQbFv7B.png) Refresh Transactions ![](https://i.imgur.com/Q22BeXC.png) The balance on `0x7984Ebb42AbD280FA31A4144357adD5EB3A16884` ![](https://i.imgur.com/dfiiurh.png) ## References 1. Vite Guide : [https://vitejs.dev/guide/](https://vitejs.dev/guide/) 2. Ethers Library V5 : [https://docs.ethers.org/v5/getting-started/](https://docs.ethers.org/v5/getting-started/) 3. Ethers Library V6 : [https://docs.ethers.org/v6/](https://docs.ethers.org/v6/) 4. Wallet development article : [https://atila.ca/blog/tomiwa/how-to-make-a-blockchain-crypto-wallet-like-metamask-with-chatgpt-react-typescript-and-ethersjs](https://atila.ca/blog/tomiwa/how-to-make-a-blockchain-crypto-wallet-like-metamask-with-chatgpt-react-typescript-and-ethersjs) 5. Wallet development video : [https://www.youtube.com/watch?v=CPxekpYYDDY](https://www.youtube.com/watch?v=CPxekpYYDDY) 6. ChatGPT : [https://openai.com/blog/chatgpt](https://openai.com/blog/chatgpt) 7. Multisig knowledge : [https://academy.binance.com/en/articles/what-is-a-multisig-wallet](https://academy.binance.com/en/articles/what-is-a-multisig-wallet) 8. Aqua Wallet Github : [https://github.com/atilatech/aqua-wallet](https://github.com/atilatech/aqua-wallet)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully