Infura Rinkeby – Problem with UnlockAccount on Rinkeby via Infura

infuranethereum

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?

Best Answer

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.


Related Topic