1

Solidity newbie here...:

 function transfer(address payable to, address sender) public onlyadmin {
         to.transfer(msg.value);

     }

what I want to achieve is sending from the contract's balance so I guess this.balance should be the correct way and not msg.value? Thanks!

3

Transfer moves money from contract's account to the beneficiary one, while balance is a lookup function that takes one arbitrary address as input and gives back its balance.

msg.value is the amount of Ether send along with the message. If you want to send all money of the contract you have to write something like that:

function f(address payable beneficiary) public {
    beneficiary.transfer(address(this).balance);
}

If you write something like that:

function f(address payable beneficiary) payable public {
    beneficiary.transfer(msg.value);
}

Whenever, the msg.sender sends msg.value Wei to the contract. The latter transfers the money to the beneficiary. In this case the smart contract is a broker that gives the received money to the beneficiary one.

Your Answer

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

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