0

Smart contract code:

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract AddressWallets {

  // variables

  address owner;
  uint funds;
  bool transferFund;

  constructor() payable {
    owner == msg.sender;
    funds == msg.value;
    transferFund = false;
  }

  modifier onlyOwner{
    require(msg.sender == owner);
    _;
  }

  modifier fundTransfered{
    require(transferFund == true);
    _;
  }

  // list of wallet address

  address payable[] investorWallets; 

  // map through all the wallet addresses

  mapping(address => uint) investors;

  //Write a payable function called payInvestors which takes the parameters address and amount.

  function payInvestors(address payable wallet, uint amount) public {
    //Write logic in the function so that it can add new wallets to investorWallets and fill them with amounts of your choosing.
    investorWallets.push(wallet);
    investors[wallet] = amount;
  }

  function sendEthers() private fundTransfered {
    for( uint i = 0; i < investorWallets.length; i++) {
      investorWallets[i].transfer(investors[investorWallets[i]]);
    }
  } 

  // fund transfer trigger....

  function hasTransfered() public onlyOwner {
    transferFund = true;
    sendEthers();
  }

  function checkInvestors() public view returns (uint) {
    return investorWallets.length;
  } 

}
2
  • 2
    Always show the full code and error message. What are you executing? What error is being thrown?
    – phaze
    Commented Mar 23, 2022 at 9:33
  • 1
    @jashit you can use GitHub Gist to share your full code. Commented Mar 23, 2022 at 9:34

1 Answer 1

0

The problem is in the constructor. Change your smart contract's contract into this:

constructor() payable {
    owner = msg.sender;
    funds = msg.value;
    transferFund = false;
}

With '==' symbol in your smart contract you're comparing the state variable's value with the global variables' value in solidity! On the contrary with '=' symbol you're assigning your state variable with the value of global variables.

Note: Remember to put a value into msg.value textbox in remix ide before deploy it! Otherwise the hasTransfered() function doesn't work because the smart contract's balance haven't a ETH to send to investors.

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.