0

I wanted to assign put in atleast 1 ether inside the balance of the owner of the contract.

pragma solidity ^0.8.0;

contract EtherWallet {
    
    address public  owner;
    mapping(address => uint) investments;
    // mapping(address => uint) balanceOfAccounts;
    // uint256 public initialBalance;
    
    constructor() payable{
        owner = payable(msg.sender);
        // initialBalance = _amount;
        investments[msg.sender] = 134 * (1 ether);
        payable(owner).balance += msg.value;
        // balanceOfAccounts[owner] += initialBalance * 1000000000000000000; 
    }
    
    modifier onlyOwner {
                require(
                    msg.sender == owner,
                    "caller is not the owner"
                );
                _;
    }

    function invest() public payable {
        require(msg.value < 0.001 ether);
        investments[msg.sender] += msg.value;
        if(investments[msg.sender] > investments[owner]) {
        owner = msg.sender;
        }
    }
    function getInvestments() public view returns (uint) {
        return investments[msg.sender];
    }

    function withdraw() public  onlyOwner {
       payable(owner).transfer(address(this).balance);

    }

    function deposit() payable public onlyOwner{
        // balanceOfAccounts[msg.sender] += msg.value;
    }
    
    function send(address payable to, uint amount) public onlyOwner{
        if (msg.sender == owner) {
            to.transfer(amount);

            return;
        }
        revert('Sender is not allowed');
    }
    
    function balanceOf() view public returns(uint) {
        return address(this).balance;
        // return balanceOfAccounts[msg.sender];
    }

    fallback() external payable{}

    receive() external payable {
        require(msg.value > 0 && investments[msg.sender] > 0);
        owner = msg.sender;
    }

}

don't mind the commented parts.

1
  • What are you trying to achieve? In remix initially every account has 100 ether. In the DEPLOY&RUN tab there's a "VALUE" box where you can indicate how much ether will be transferred to the contract on deployment/transaction.
    – Ismael
    Aug 6 at 17:12

0

Your Answer

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

Browse other questions tagged or ask your own question.