So, I've started
bitcoind and through
bitcoin-cli, I've generated new address(
bitcoin-cli getnewaddress "USEREMAILID") and assigned it to the users.
Please don't do this. You are using the accounts system in Bitcoin Core which is deprecated, slightly unreliable/has weird behavior, and will be removed in the future.
Maintain your own accounting system outside of Bitcoin Core. Just have a database with addresses and their associated user.
Now my question is, whenever user starts buying a product, he will execute command (
bitcoin-cli sendfrom) and for doing that,
Why? Why don't you just change their balance on the website and just leave the coins there? There is no need to make actual transactions that move the coins to you, just change it internally.
we need to first
unlock the wallet by walletpassphrase and then do the transaction. so, there would be
only 1 password which is assigned to the wallet but not every address.
No, that is not how Bitcoin Core, addresses, or accounts work. Accounts are not wallets. All of the addresses for all of the accounts belong to the same wallet. Unless you are using Bitcoin Core 0.15+ and have enabled the use of multiwallet, you are only using one wallet in Bitcoin Core. So there is only one passphrase to be used with
walletpassphrase and it unlocks the entire wallet which includes all of the addresses you have given out on your website.
Is this the correct way?
No, it is not.
The correct way is to maintain a separate database with user accounts, associated addresses, and account balance. When you transfer coins internally (i.e. from one user to another or from one user to you), update the balances in that database instead of making a Bitcoin transaction. When you want to send coins externally (i.e. user withdraws) then you send from the Bitcoin Core wallet and update your own database. When you send, just use
sendtoaddress. Do not use Bitcoin Core's accounts system and don't try to make it so that you are sending from certain addresses.
If user needs to enter his
custom password and then process the transaction, would it be possible?
No, as I explained above, that is not how this works.