I'm trying to achieve what seems like a simple goal but having trouble finding a simple solution to it. Here's my problem:
Given a private key, I would like the simplest way to "inject" this key into a web app context so that all subsequent usage of the web3
object uses this as web3.eth.defaultAccount
.
Before someone brings up security issues, I would like to emphasize that we can ignore security implications for now. It's a special case and I have solutions to deal with the security issue as long as this is possible.
The only solution I've found so far has been to create a custom provider and instantiate the Web3
instance with this custom provider which overrides certain methods like sendTransaction
, etc.--this is how MetaMask seems to work using https://github.com/MetaMask/provider-engine.
But setting up all these custom providers just for what I'm trying to achieve--take a private key string and turn it into web3.eth.defaultAccount
--feels like an overkill.
Any help would be appreciated. Thank you!