[Ethereum] how to convert string to Address

solidity

I want to convert string data to address type.I know that we can directly use address type in the parameters, but for some reason I want to convert it from string to address.

sample code

function check(string _address,string _name,string _password) public returns (string)
{

    address add=address(_address);
   if(!checkUser(add))
    {    
        Useraccnts.push(add)-1;
          Users  storage myuser=users[add];
          myuser.name=_name;
          myuser.password=_password;

        return "true";
    }
    else
    {
        return "false";
    }         

}

I got JSON-RPC: internal error while executing this function. so I want to check whether it would be resolved if I change the address to a string. If you know how to resolve the JSON-RPC error please help me out.

registerUser: function() { 
    var self = this; 
    var acc=account; 
    var name=document.getElementById("name").value; 
    var password=document.getElementById("password").value; 
    var meta; 
    CoinFlipper.deployed().then(function(instance) { 
        meta = instance; 
        return meta.check.call(acc,name,password).then(function (value) { }, 

I'm using the above function in app.js.

Error: Invalid JSON RPC response: {"id":6,"jsonrpc":"2.0","error":{"code":-32603}} at Object.InvalidResponse (app.js:10374)

Best Answer

One issue with your code is that you are making a call, but your function is not constant and modifies the storage, you need to issue a standard transaction for that reason

CoinFlipper.deployed().then(function(instance) { 
    meta = instance; 
    return meta.check(acc, name, password); /// <--- without `call`
}).then(function (value) {
}); 
Related Topic