0

Like i want to Insert the value that how much ethers are transfer from my smart contract.

I tried this second day but it's not working so i'm looking for solution any help is highly appriciated

here is my contract

// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

contract Bank{
    // Implement remaining timestamp for fd,blocklist,validations(minimum amount)
    // 
    address private owner;
    constructor() {
        owner=msg.sender;
    }
    mapping(address=>uint256)  accounts;
    mapping(address=>bool) public CheckAccount;
    mapping(address=>uint256) public fdAmount;
    mapping(address=>bool)  blockedAcc;
    uint fees=0.00005 ether;
    uint feesColl=0;

    
    function createAcc() public  {
        require(CheckAccount[msg.sender]==false,"Account Aleready Created Succefully");
        require(blockedAcc[msg.sender]==false,"You are blocked by the Owner");
        accounts[msg.sender]=msg.sender.balance;
        CheckAccount[msg.sender]=true;

    }

    function createFD() public payable {
        require(blockedAcc[msg.sender]==false,"You are blocked by the Owner");
        require(CheckAccount[msg.sender],"Create Account First");
        payable(address(this)).transfer(msg.value);
        payable(address(this)).transfer(fees);
        // _to.transfer(msg.value);
        // _to.transfer(fees);
        fdAmount[msg.sender]+=msg.value / 1 ether;
    }

    function getBalance(address _address) public view returns(uint256){
        require(blockedAcc[msg.sender]==false,"You are blocked by the Owner");
        // require(!accounts[msg.sender])
        return _address.balance / 1 ether ;
    }

    receive() external payable {}
    
    function getContractBal() public view returns(uint){
        require(blockedAcc[msg.sender]==false,"You are blocked by the Owner");
        return address(this).balance / 1 ether;

    }

    function WithdrawFD() public payable {
        require(blockedAcc[msg.sender]==false,"You are blocked by the Owner");
        //  _to.transfer(msg.value);
        // .call.value(address(this).balance)()
        payable(msg.sender).transfer(address(this).balance);
        fdAmount[msg.sender]-=msg.value / 1 ether;
    }

    function CloseAcc() public{
        require(CheckAccount[msg.sender]==true,"Account Not Exist,Create Account First");
        require(blockedAcc[msg.sender]==false,"You are blocked by the Owner");
        CheckAccount[msg.sender]=false;
        delete accounts[msg.sender];

    }
// If after created the account user marked as blacklisted then account should be closed
    function BlockUsr(address _add) public {
        CloseAcc();
        require(msg.sender == owner,"Only Owner Has the Permission");
        blockedAcc[_add]=true;

    }
     function UnBlockUsr(address _add) public {
        require(msg.sender == owner,"Only Owner Has the Permission");
        
        blockedAcc[_add]=false;

    }


}

The problem is with withdraw function when i call the function the all amount is withdrawn from smart contract how want to specify the amount like msg.value

1 Answer 1

0

Just add 1 more param in you withdraw function :

function WithdrawFD(unit amount) public payable {
    require(blockedAcc[msg.sender]==false,"You are blocked by the Owner");
    //  _to.transfer(msg.value);
    // .call.value(address(this).balance)()
    require(amount >= address(this).balance);
    payable(msg.sender).transfer(amount);
    fdAmount[msg.sender]-=msg.value / 1 ether;
}
1
  • Thanks for your help, I appreciate it
    – MindCoder
    Feb 12, 2023 at 5:19

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.