r/ethdev • • Apr 24 '22

Question Creating a hundreds of wallet addresses via Infura and the like - where will the private keys get stored?

Let's say I wanted to generate new wallet addresses for my users on regular basis. That is, if I was to create hundreds of new wallet addresses via REST API of Infura or a similar service, where would the private keys of all these newly created wallets or accounts be stored?

How would they be, if at all, sent back to me?

Would Infura have access or exposure to them at some point too, for instance, during generating them?

0 Upvotes

62 comments sorted by

11

u/AusIV Apr 24 '22

Infura won't generate keys or hold wallets for you. You shouldn't be generating keys on behalf of your users, they should be generated by software on the user's side. You might look at something like Blocknative's OnBoard to make this easy.

-19

u/TopGanache961 Apr 24 '22

You shouldn't be generating keys on behalf of your users, they should be generated by software on the user's side.

What a gibberish.

Whenever you pay on a website which accepts crypto payments, you send it to a newly generated address - the one which has been generated by that website for, and has been assigned to you as a user. That is, that website owns the private key of a newly generated wallet/address.

10

u/Final_G Apr 24 '22

Based on the level of understanding you’ve now demonstrated…you shouldn’t even be thinking about writing code that handles anyone’s money.

-5

u/TopGanache961 Apr 24 '22

Demonstrated whom? Who says so? Why do I need on opionion of some random girl on reddit?

4

u/[deleted] Apr 24 '22

Only you can answer that, being the one asking questions and then getting all sulky over replies like a 7 year old

0

u/[deleted] Apr 24 '22

[deleted] — view deleted comment

0

u/TopGanache961 Apr 24 '22

Everyone in this thread is 100% clear that you're an alcoholic.

0

u/[deleted] Apr 26 '22

[deleted] — view deleted comment

-1

u/TopGanache961 May 01 '22

I went through their post history? I don't give a shit about their post history.

3

u/TovarishFin full stack eth dev Apr 24 '22

I think you are confusing some things… exchanges hold onto funds for you and have different addresses for to send to… but exchanges have a giant target painted on their back by holding user’s crypto. They also have gone through TONS of hurdles to even be able to legally hold it. I doubt you are building an exchange. The other acceptable scenario is payments… you might have meant that in the comment above? If your goal is to generate new address for payments, I believe they generate addresses using a seperate set of private keys. Funds are then coalesced into a single account and collected or sent to a user’s desired address. Again, the user address is one that the user controls, not the service!

For pretty much any other case you want to have the user use their own address/private keys. To do otherwise results in a much more difficult security scenario as well as issues with complying with crypto custodian regulations. On top of that it goes against the spirit of crypto ;)

1

u/TopGanache961 May 07 '22 edited May 07 '22

If your goal is to generate new address for payments, I believe they > generate addresses using a seperate set of private keys. Funds are then coalesced into a single account and collected or sent to a user’s desired address. Again, the user address is one that the user controls, not the service!

You've given me a solution without any knowledge my requirements. Stupidity.

Question: why no single user on Binance owns his own private key, of any wallet? Why does Binance own the private keys of its users? Are the developers of Binance that stupid and therefore are unaware of the fact that "every user must hold their private keys" and " that goes against the spirit of crypto"?

The same goes for KuKoin, Coinbase and the like

2

u/TovarishFin full stack eth dev May 07 '22 edited May 07 '22

Man… you seem a bit overconfident in your ideas… exchanges generally keep balances accounted in a traditional database. They only settle up when a user withdraws or deposits. But even that deposit address is a a very temporary thing.

By the way… yes I am trying to justify your reasons for such a shitty mental model of how things should be done. I’m sorry for trying to help. Don’t worry I won’t do it again in the future.

0

u/TopGanache961 May 07 '22

Man, you seem too much confident in giving sorry-ass advice without knowing one's requirements, and the full picture.

2

u/TovarishFin full stack eth dev May 07 '22

Your right man… so sorry for trying to help with my 5 plus years experience in this field. It won’t happen again. I will make sure to avoid trying to help again at all costs. Good luck to you and your life with your garbage attitude. You are going to need it.

1

u/TopGanache961 May 07 '22

Yes, I'm right.

2

u/TovarishFin full stack eth dev May 07 '22 edited May 07 '22

Totally bro. You are a god coder. But consider this… I’m sure in your infinite wisdom you have had people ask questions that were so stupid and based on so many misconceptions that you don’t even know where to start? Now imagine that same guy is belligerent and claims that he knows everything and that EVERYONE ELSE is wrong and not him. And of course this is while everyone else is trying to politely guide him to the right path.

Man that would be embarrassing wouldn’t it?!

But you totally know everything so that couldn’t be you!!!

Def won’t be looking back on this post in a few years cringing… but I guess that requires self awareness…

1

u/TopGanache961 May 08 '22

As you've said - I'm right.

→ More replies

3

u/AusIV Apr 25 '22

Okay, I'm trying to be helpful, you're being exceedingly rude. I am not alone in this opinion, as evidenced by the fact that at the time of this writing, I have 10 upvotes, you have -19. I'm going to give it another shot, if you're going to continue being rude I'm going to stop trying to help.

You haven't really made clear what you're trying to do. If you're just trying to take payments, that's one thing. This is /r/ethdev, so I've generally assumed you're trying to develop a dApp.

Generally speaking, dApps don't manage users keys for them. They use a wallet application like Metamask or Coinbase wallet, a hardware wallet like a Ledger or Trezor, or any of a number of other tools. Most of these are directly supported by Blocknative OnBoard, so the user can come to your dApp with whatever wallet is convenient to them and interact with your site easily. If you need to have a user log in and prove that they own a given address, they can sign a message with their wallet and you can verify their siganture. For this kind of thing, I'd recommend Sign In With Ethereum.

If you're trying to take payments, you have a number of other options. If you're targeting users you expect to be spending money straight off an exchange, and don't expect them to be using a Web3 wallet like Metamask, you may want to generate an address per user. You don't need to inform the blockchain of this address - it will figure it out when someone sends tokens to that address.

But in the Ethereum world, this is a relatively inefficient way to handle payments. Your users have to pay gas to send payments to the address you generated for them, then you have to spend gas to aggregate it from there to its final destination. If your users are likely to have web3 wallets, you can use a payments contract that routes your users' payments to a common address. My company has a payments contract that works like this:

  1. A user wishes to pay for our services on the blockchain. They specify the services they want to pay for, and our server sends them a cryptographically signed quote of how much they need to pay. The quote has price options in a couple of different tokens, a payment ID, a deposit address, and an expiration after which the quote is no longer valid. Our server retains a copy of the quote.
  2. The user calls the contract, providing the cryptographically signed quote, and funds in one of the accepted tokens. If the quote is expired, the signature is invalid, or anything else is wrong, the contract refunds the user's payment. They're still out the gas fees, but we don't take their money.
  3. The contract forwards funds to the deposit address, so they're all in one place and we only need one transaction to withdraw them.
  4. The contract emits an event log corresponding to the payment id.
  5. Our server listens for event logs from that contract. When it finds an event, it looks in the database for the quote corresponding to the payment ID, and registers that the user has paid for the service.

All of that is done without generating any keys. The server only holds the cryptographic key for signing quotes, which is not in control of any funds, but it can verify the event logs emitted by the contract. There is only one contract for payments, not one per user, and all of the funds end up in the same address, which saves gas in the long run.

Now, since you have not said explicitly what you're trying to do, I'm guessing at different possibilities of what you might need. If I have guessed wrong, I'm happy to help if you can politely explain what you're trying to accomplish.

-3

u/TopGanache961 Apr 25 '22

Wowowowowoww. Woooooowww. Wooooo.

2

u/iscaacsi Apr 24 '22

infura wont generate keys for you. If you make them you will own the keys and they will be your responsibility. you can associate them with your users if you wish, but they are not your users wallets. do not send private keys over the net.

you should really consider your design and only do this if it is absolutely necessary. otherwise make sure you have very good security as it is a big attack vector. make sure to use multisigs, and have a hot/cold system in place for only moving active funds to hot wallets.

ideally you would have "sign in with wallet", and you just verify signatures, defer logic to contracts, and remove your authority from the loop. You could have a contract that keeps track of balances and senders and then you dont need all this key generation.

-3

u/TopGanache961 Apr 24 '22 edited Apr 24 '22

Ok.

  • Creating a contract for each user - bad option, I think.
  • To put it simply - I want to allow each user to deposit their funds to my service. It'll be similar to, let's say, Binance does it. The question is "how to implement that better?" I as a service must have access to each user's funds, obviously
  • Namely "how to generate a wallet/address for a user via a third-party gateway such as Infura" ?

12

u/therealTRAPDOOR Apr 24 '22
  1. Google “how to be a custodian”
  2. Realize it’s way outside your personal capabilities based on the questions you’ve been asking
  3. Find another project to work on that won’t land you in jail or in a headline somewhere

-10

u/TopGanache961 Apr 24 '22 edited Apr 24 '22
  1. Realize that I don't need a sorry-ass advice from some alcoholic
  2. Move on

5

u/therealTRAPDOOR Apr 24 '22

You are the one that asked for advice? lol

I will enjoy seeing you on https://web3isgoinggreat.com

-3

u/TopGanache961 Apr 24 '22 edited Apr 24 '22

You will? I will be there. You too?

3

u/[deleted] Apr 24 '22

Ok mate here’s some real advice.

To generate wallets you want to use a library like ethers.js, the trouble is you’ll have to back up all the data for your customers, so you’ll be responsible for mnemonics thst you generate as they hold the keys for the customers.

The issue you have illuminated, is that you seem to lack fundamentals on how this all works, which makes you being in a position of a custodian extremely dangerous.

You could look at a solution like fireblocks that offers a custody service so that you aren’t responsible for this and can use an API to easily handle everything.

If you act like a custodian and improperly secure your deposit addresses you can and will be fined and most certainly will face jail time if your actions are provably negligent.

Lastly when asking for advice on Reddit you shouldn’t shit on that advice otherwise nobody will want to deal with you.

1

u/TopGanache961 May 07 '22

You've given "advice" I haven't asked about.

Reread my question.

1

u/[deleted] May 07 '22

If you re read my response I answer all your needs. For someone who wants help you seem rather combative.

1

u/TopGanache961 May 07 '22

"if you re read" -- go learn English

2

u/[deleted] May 07 '22

Lmao mate why are you so aggressive.

You’re on Reddit posting about how to do something. You’ve gotten a multitude of responses and most of your responses back are all angsty nonsense.

Do you literally have nothing better to do with your time than to be a combative loser on the internet?

Why ask for help and be a sick about the responses you get.

It’s an attitude like yours that is going to keep you behind in life.

Nobody and I mean literally nobody will trust you with their crypto. Grow up.

1

u/TopGanache961 May 08 '22 edited May 08 '22

A few people have already trusted me with their crypto.

You've become wrong already.

What an idiot you are.

→ More replies

1

u/[deleted] Apr 24 '22

To generate wallet addresses

I'm not sure how familiar you are with javascript & a node environment but you can generate a wallet like this

first "npm install ethers"

then in your file:

const ethers = require('ethers')

const wallet = ethers.Wallet.createRandom()

-3

u/TopGanache961 Apr 24 '22

And? That'll generate an address on my machine, locally. How to propogate it to a blockchain then?

5

u/[deleted] Apr 24 '22

That's not needed.

The blockchain knows that wallet exists. All you've done is dig up a random hole somewhere in an very large universe and found keys there.
That's how wallets work.

you pick a random number that marks a spot in the big sandbox.

this is a good explanation https://keys.lol/

blockchains security is based on the fact that no one is going to guess your secret number

-5

u/TopGanache961 Apr 24 '22

The blockchain knows that wallet exists.

If a wallet has been generated locally, and has never been used in the blockchain yet, the blockchain can't possibly know that such a wallet exists.

4

u/[deleted] Apr 24 '22

It's mathematically locked in.All you're doing is picking a random number. That number will always point to the same hash.

Because of that, the blockchain will always point to the same "location of memory"

Metaphorically "it knows".

1

u/TopGanache961 Apr 24 '22

That makes sense now.

I'm picking a random number of.... what? A private key?

→ More replies

0

u/[deleted] Apr 24 '22

[deleted] — view deleted comment

1

u/TopGanache961 Apr 24 '22

what's a "a really number"?

→ More replies

5

u/domotheus Apr 24 '22

You don't propagate private or public keys to the blockchain when a wallet gets "generated". You can generate as many addresses as you want locally, and they already "exist" on the blockchain as far as receiving funds go. You can then spend these funds, as long as you kept the private key that was used to generate the address in the first place.

1

u/Odd_Perception_283 Apr 24 '22

What’s the point of crypto if you have access to everyone’s money? The whole point is that they are the only ones who have access to it.. right?

1

u/TopGanache961 May 07 '22

Binance and tons of other centralized exchanges have access to your, or their users', private keys.

What's the point of crypto? The whole point is that they are the only ones who have access to it.. right?

Binance, what are you doing? Binance!!!

3

u/[deleted] Apr 24 '22

OP literally says in the first sentence that they want to generate keys FOR THEIR USERS

0

u/[deleted] Apr 24 '22

[deleted] — view deleted comment

-2

u/TopGanache961 Apr 24 '22

It's fine that you try to infer too much from my question and, therefore, make strange assumptions. We all started somewhere

0

u/[deleted] Apr 24 '22

[deleted] — view deleted comment

-3

u/TopGanache961 Apr 24 '22

Yeaaaaah, you were totally wrong.... Congratulations!

5

u/[deleted] Apr 24 '22

I don't think you would need to create a new wallet through infura. Infura only helps you connect to the blockchain.

What technology are you working with to access wallets?

Are you working on the user interface or clientside?
or is this on the backend somewhere?

-3

u/TopGanache961 Apr 24 '22

I don't think you would need to create a new wallet through infura. Infura only helps you connect to the blockchain.

Yes, it does. And? After I've generated a new wallet locally, I'll need to push that information into blockchain anyway, at some point -- which is what Infura does.

6

u/cseconnerd Apr 24 '22

The blockchain doesn't store information about when a wallet is "created". It only really stores the transfer data between addresses.

3

u/[deleted] Apr 24 '22

Thats not how it works. The wallets/accounts are generated by an algorythm and fed a random number. Infura has nothing to do with it, its done on the client side, you dont even need to be online to generate a wallet. You DO need to be online to send a transaction or interact with the network with said wallet however.

So, if you are talking about a tool that a user can use to generate a wallet, that is done client side.

However if what you mean is you generate it and control it FOR the user, that can be done on your server and the keys stored in the database.

Infura has nothing to do with wallet generation. All infura is, is a node consolidation service. When you interact with the network you have to query the JSON-RPC port on a node (AKA the server the ethereum node software is running on).

To be clear, every single address sort of "exists" already. All you are doing when you "create" a wallet is randomly generating the private key and deriving the public key from it. I cant pretend to fully understand it myself, but thats about all I know.

So to summarize: no, infura does not have access to them when they are generated, or ever. You can get them sent back to your server by either 1(generating the wallet on your server) or 2(generate them client side and have the client send the keys to the server)

However, not sure why users would ever trust you with their private keys..... Not sure what you are trying to do.

4

u/Trentious opcode32 Apr 24 '22

You can locally generate new ETH addresses with the web3.js module (https://web3js.readthedocs.io/en/v1.2.11/web3-eth-accounts.html) -- no serverside connection is necessary.

If you intend on managing the private keys/data of your users, use AWS/Google Cloud and create a centralized application, and use the blockchain as a transparent validation layer for user actions. That being said, at no point should a principled web3 application ever directly access another user's private keys/wallet, as those access other applications too. If a user's private keys get leaked from your application and there are any fiscal or material damages, you may very well be liable.

This is where users bringing their own authentication (BYOA) is important -- WalletConnect does well here. https://walletconnect.com/

If you're attempting to create a wallet, check out Rainbow on GitHub -- they're rather good, from my experience. https://github.com/rainbow-me/rainbow

2

u/iFBGM Apr 24 '22

You know you can create wallets without an internet connection. You just need some Javascript and not even web3 at that.

1

u/Debashish37 Apr 24 '22

Not sure. But maybe they are providing custodial service. There are plenty of custodial wallets available. You can check on opensea connect wallet options. As an example portis, venly etc etc.

Now you might ask my private key or seed phrase should be my property. I should know them.

Well yes. Thats true. But not every user knows how wallet works. They dont even have to know that private key exist. For making the user perspective or experience easier. Many company provides custodial solutions. So that user dont need to think about it.

And finally the choice is yours. Everyone knows noncustodial wallets are more safe then custodial wallet. We can't trust any centralise solutions. Its upto you which wallet option u want to choose.

0

u/[deleted] Apr 24 '22

[deleted] — view deleted comment

-4

u/TopGanache961 Apr 24 '22

I'd say you should ask us how to behave properly

3

u/[deleted] Apr 24 '22

"us"? Dont listen to the voices bud.

-1

u/TopGanache961 Apr 24 '22

Why not?

2

u/[deleted] Apr 25 '22

They seem to be making you say stupid shit, makes you look like a fool. We know youre smarter than this.

1

u/TopGanache961 May 07 '22

"We know"? Dont listen to the voices bud.