0

When I am executing the program on the remix IDE (got from internet), it asks me the address, _wallet, which I am passing in the constructor. Remix IDE shows me 3 addresses: Account, Deploy _wallet and Deployed Contracts. In the code, I am using the only the wallet address retrieved from wallet. What the statement

wallet.transfer(msg.value)

would do? Will it transfer Ether to the Account address. What is the difference between the 3 address and their usage.

pragma solidity 0.5.4;
  contract MyContractEtherEvents {
    mapping(address => uint256) public balances;
    address payable wallet;
    event Purchase(
        address indexed _buyer,
        uint256 _amount
    );

    constructor(address payable _wallet) public {
        wallet = _wallet;
    }

    function() external payable {
        buyToken();
    }

    function buyToken() public payable {
        balances[msg.sender] += 1;
        wallet.transfer(msg.value);
        emit Purchase(msg.sender, 1);
    }
}

Somebody please guide me.

Zulfi.

enter image description here

1 Answer 1

1

What is the difference between the 3 addresses?

  • Account: the account that you are currently using in order to execute transactions (i.e., deploy contracts and/or call contract functions); It has to be unlocked on your environment
  • Deploy _wallet: the input argument that you need to pass to the constructor of contract MyContractEtherEvents in order to deploy it
  • Deployed Contracts: a list of addresses of contracts that you have already deployed

What will the statement wallet.transfer(msg.value) do?

It will transfer the amount of ether that the user has just passed to your contract when he or she called the function; it will transfer that amount of ether from your contract to the address wallet (which you had passed as an input argument to the constructor of the contract when you deployed it); assuming that you have the private key of this address, you will be able to withdraw that amount, i.e., transfer it to anywhere you want.

2
  • In this program, user can only pass Ether to the wallet address. Can a user pass Ether to the Account address or to the Deployed contract address?
    – zak100
    Jan 21, 2020 at 19:55
  • If I am assigning 2 to the value field and changing the wei to Ether, then 2 Ethers are deducted from account address and 2 Ether are added to the wallet address.
    – zak100
    Jan 21, 2020 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.