0

Can somebody help me fix this error in my bank program enter image description here

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

contract banking{
  mapping(address=>uint) public user_account;
  mapping(address=>bool) public user_existance;

  function createAcc() public payable returns(string memory){
      require(user_existance[msg.sender]==false,'Account already in the database');
      if(msg.value==0){
          user_existance[msg.sender]=true;
          user_account[msg.sender]=0;
          return 'Your account is now in the database';
      }
      require(user_existance[msg.sender]==false,'Account already in the database');
      user_existance[msg.sender] = true;
      user_account[msg.sender] = msg.value;
      return 'account created';
  }
  
  function deposit() public payable returns(string memory){
      require(msg.value>0, 'Dont enter value 0 while depositing');
      require(user_existance[msg.sender]==true, 'Account is not in the database');
      user_account[msg.sender]=user_account[msg.sender]+msg.value;
      return 'Deposit Succesfully';
  }
  
  function withdraw(address payable userAddress, uint amount) public payable returns(string memory){
      require(user_existance[msg.sender]==true, 'Account is not in the database');
      require(amount>0, 'Dont enter value 0 while withdrawing');
      require(user_account[msg.sender]>amount, 'Insufficient Balance');
      user_account[msg.sender]=user_account[msg.sender]-amount;
      msg.sender.transfer(amount);
      return 'withdrawal Succesful';
  }
 
  function TransferAmount(address payable userAddress, uint amount) public returns(string memory){
      require(amount>0, 'Dont enter value 0 while sending');
      require(user_existance[msg.sender]==true, 'Account is not in the database');
      require(user_account[msg.sender]>amount, 'Insufficient Balance');
      require(user_existance[userAddress]==true, 'The Account you want to transfer to does not exist in the database ');
      user_account[msg.sender]=user_account[msg.sender]-amount;
      user_account[userAddress]=user_account[userAddress]+amount;
      return 'transfer succesfully';
  }
  
  function user_accountBalance() public view returns(uint){
      return user_account[msg.sender];
  }
  
  function accountExist() public view returns(bool){
      return user_existance[msg.sender];
  }
  
}
1
  • Can you help me out @DrGorilla.eth Jul 7, 2022 at 9:47

1 Answer 1

0

two options

payable(msg.sender).transfer(amount);

but transfer is deprecated, so call is the better option

(bool ok, ) = msg.sender.call{value: amount}("");
2
  • Could you tell me how to run tests on hardhat for this Jul 7, 2022 at 12:17
  • you mean unit testing your functions?
    – sola24
    Jul 7, 2022 at 13:50

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.