Solidity code not giving desired output when input given through Flutter developed application

26 Views Asked by At

So I am making a web3 application for my final year project in civil engineering degree

I initialized my http clients

 Client? httpClient;
  Web3Client? ethClient;
  @override
  void initState(){
    super.initState();
    httpClient = Client();
    ethClient = Web3Client(infura_url, httpClient!);
  }

inputted all my functions into android studio

Future<DeployedContract> loadContract ()async{
  print('loading contract');
  String abi = await rootBundle.loadString('Assets/abi.json');
  String ContractAddress = contractAddress;
  final contract = DeployedContract(ContractAbi.fromJson(abi, 'Login'), EthereumAddress.fromHex(ContractAddress));
  return contract;
}
Future<String> Login(Web3Client ethClient, String _username, String _password)async{
  DeployedContract contract = await loadContract();
  print('contract loaded');
  final response = await ethClient.call(contract: contract, function: contract.function('login'), params: [_username,_password],);
  print(response);
  return response[0] as String;
}

My flutter UI code which takes values from textfield and sends it to the contract is stated below

 onPressed: () {
              String Utext = UserText.text;
              String Upass = PassText.text;
              print('a$Utext,b$Upass');
              Login(ethClient!, Utext, Upass).then((String isLoggedin){
                print(isLoggedin);
                if(isLoggedin == 'yes'){
                  Navigator.push(context, MaterialPageRoute(builder: (context) => Client_init(),));
                };
              });
            },

The relevant part of my solidity code is also stated below

function login(string memory _username, string memory _password) public view returns (string memory) {
        User memory user = users[msg.sender];
        string memory isLoggedin;
        if(keccak256(abi.encodePacked(user.username)) == keccak256(abi.encodePacked(_username)) && 
            keccak256(abi.encodePacked(user.password)) == keccak256(abi.encodePacked(_password))){
            isLoggedin = "yes";
        }
        else{
            isLoggedin = "no";
        }
        return isLoggedin;
    }

Now whenever I enter the right value into my textfield into the flutter app and press login, I get the answer [no], even though I should get [yes], this means that my app is able to reach this contract and decode it, so there is nothing wrong with my abi or my ethClient initialization, neither there is something wrong with the way I handle this async function right? then why do I still get [no] as an answer when I should get yes.

Plus on a side not, my register function throws an error of 32000 invalid sender, eventhough I do that transaction with my personal key, can anyone tell me for what reasons do I get invalid sender errors?

Please help a sleep deprived student out :,)

I wanted to input a name and password in my flutter application and for the app to verify it from smart contract and give me an output of [yes]

0

There are 0 best solutions below