Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a new wallet #16

Open
omercakici opened this issue Feb 19, 2025 · 2 comments
Open

How to create a new wallet #16

omercakici opened this issue Feb 19, 2025 · 2 comments

Comments

@omercakici
Copy link

Hi,

How to create a new wallet for each user?

@Marygka
Copy link

Marygka commented Feb 19, 2025

Hello @omercakici
Creating a new wallet for each user typically involves generating a unique pair of cryptographic keys (a public key and a private key) for them. Here's a step-by-step guide on how to do this:

  1. Choose a Library: First, select a library that supports wallet creation. Popular options include ethers.js or web3.js for Ethereum-based wallets. These libraries provide functions to generate wallets easily.

  2. Generate a New Wallet: Use the library to create a new wallet. Here’s an example using ethers.js:

    const { ethers } = require("ethers");
    
    // Generate a random wallet
    const wallet = ethers.Wallet.createRandom();
    
    console.log("Address:", wallet.address);
    console.log("Private Key:", wallet.privateKey);
  3. Store the Wallet Securely: Once you generate the wallet, you need to store the private key securely. This is crucial because anyone with access to the private key can control the wallet. Consider using secure storage solutions, such as encrypted databases or hardware security modules.

  4. Associate Wallets with Users: When a user registers or is created in your system, associate the generated wallet address with their user profile in your database. This way, you can easily retrieve the wallet for each user when needed.

  5. Implement Backup and Recovery: Provide users with a way to back up their wallets. This could involve giving them a mnemonic phrase (seed phrase) that they can use to recover their wallet in case they lose access.

  6. Test the Wallet Creation: Before deploying, test the wallet creation process thoroughly to ensure that each user gets a unique wallet and that the wallets function correctly.

By following these steps, you can create a new wallet for each user securely and efficiently.

@omercakici
Copy link
Author

omercakici commented Feb 19, 2025

I got it. But PI network accounts start with G..... How can i encode from hex code (which generated by web3 or ethers lib.) to Pi network Account Address Format?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants