0

I got "405 Method Not Allowed" error when I tried to unlock an account I created on MetaMask. Here is the code:

string privateKey = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
string senderAddress = "0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

var account = new Account(privateKey);
var web3 = new Web3(account, "https://rinkeby.infura.io/<token>");

var password = "xxxxxxx"; // where does this come from? the meta mask password???

// error on the line below
var unlockResult = await web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, password, new HexBigInteger(120));

What have I done wrong? Where does 'password' come from?

3 Answers 3

0

Password in this case is used to unlock keystore file, stored locally on your machine (where node is running). Usually it reside in ethereum client folder under the subfolder keystore. Metamask doesn't store your keystore this way, it uses browser data instead.

If you wan't to unlock your wallet you need to create another account somewhere where keystore file is generated by default after account creation (with password).

Or you can use your MetaMask account and Export Private Key to further use some web3py (for example) to generate your own keystore file:

web3.personal.importRawKey(self, private_key, passphrase)

Adds the given private_key to the node’s keychain, encrypted with the given passphrase. Returns the address of the imported account.

After you generate your keystore file just put it in the keystore folder in your client folder and the client should automatically detect it and next time you try to unlock account with the correct password it should work as expected.


3
  • I do have the private key. Is there a way to unlock account in Nethereum with just the private key? Commented Mar 20, 2018 at 6:16
  • @AllenZhang according to nethereum.readthedocs.io/en/latest it has Geth management API (admin, personal, debugging, miner) and Parity management API, so you will be able to sign raw transactions using your private key, but not unlock account. It was discussed here. Commented Mar 20, 2018 at 6:34
  • This question has your solution. You can send a signed transction to infura
    – Ayushya
    Commented Mar 20, 2018 at 6:43
0

Password is required if you have personal api enabled on the RPC. But infura does not enable this RPC-API, because if it does so, it will be a great security concern.

Instead, you are required to send a signed transaction.

0

The fact that I have the private key in the code means I don't need to unlock my account.

I just go ahead and do whatever I need to do after the account is unlocked.

Credit goes to Nethereum's Auther Juan Blanco.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.