[Ethereum] how to fetch private key of metamask account while transaction using web3.js

contract-developmentethereumjsmetamasktransactionsweb3js

I have a problem,
What I want is to user to come at my website, from where he/she can connect to its metamask wallet account, after connecting I want them to allow to do transaction from some specific token address, to admin metamask account, but for transaction we require a private key of a customer's account.

In that case how I will get customer's private key to perform a transaction ? or if there any other way arounf through which I can achieve my requirement, kindly guide me to some solution.

Best Answer

Metamask doesn't expose private keys as it's a huge security issue. You shouldn't expect users to expose their private keys either. If you want to sign a transaction or arbitrary data, you can use the Metamask RPC methods. You can find the methods here. With this, you can perform data signing, encryption-decryption with the private keys, in a safe way.

Related Topic