0

I am trying to connect my wallet (Metamask) via Infura, but I receiving an error. My code:

[HttpPost]
    public async Task<IActionResult> LoginAsync([ModelBinder(typeof(AccountBinder))] Account acc)
    {
        try
        {
            Account.ValidateAddress(acc.AccountAddress);
            var web3 = new Web3(acc.AccountNetwork + "" + acc.InfuraApiKey); //infura Ropsten+ProjectID
            var balance = await web3.Eth.GetBalance.SendRequestAsync(acc.AccountAddress);  //works fine
            var etherAmount = Web3.Convert.FromWei(balance.Value); //works fine
            acc.AccountBalance = (double)etherAmount;        
            var unlockAccountResult = await web3.Personal.UnlockAccount.SendRequestAsync(acc.AccountAddress, acc.AccountPassword, 60);   //not working!!!!!!!! <- <- <-
            if (unlockAccountResult)
            {
                acc.IsValidated = true;
                return View("Login", acc);
            }
            else
                throw new WrongAccountDetails("Incorrect account or password");
        }
        catch (WrongAccountDetails ex)
        {
            ...
        }
    }

I getting this error:

An unhandled exception occurred while processing the request.
RpcResponseException: The method personal_unlockAccount does not exist/is not available
Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response)
Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response)
   Nethereum.JsonRpc.Client.ClientBase.SendInnerRequestAsync(RpcRequestMessage     reqMsg, string route)
Nethereum.JsonRpc.Client.ClientBase.SendInnerRequestAsync(RpcRequest request, string route)
Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync(RpcRequest request, string route)
RealEstate_Web_app.Controllers.AccountController.LoginAsync(Account acc) in AccountController.cs
+
var unlockAccountResult = await     web3.Personal.UnlockAccount.SendRequestAsync(acc.AccountAddress,   acc.AccountPassword, 60);

And so on....

1

Infura only supports a subset of the Ethereum JSON-RPC endpoints that web3 knows about. You can see the list in Infura's documentation.

The RPC that web3.personal.UnlockAccount is trying to use is called [personal_unlockAccount][2]. The personal module is all about maintaining a local wallet, including signing transactions and messages and creating new addresses. It makes sense that Infura would not support this module as it entails creating and storing private keys for users with is both a large security risk and a stateful operation. A cloud full-node service such as Infura is best for pure blockchain information queries such as the ones you will see in their documentatinon.

If you want to have web3 manage a wallet as in your code, you must use a different RPC provider. This can be a full node like Geth or Parity. Hopefully this answers your question.

| improve this answer | |
  • So, is there another way to check if the password is correct? – חיים חדד Oct 26 '19 at 9:30
  • It cannot be correct or incorrect, because there are no Ethereum accounts in Infura, because it's not supported. If you want to use your own accounts you'll have to use your own Geth node. – Molina Oct 27 '19 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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