Code is:

pragma solidity ^0.4.16;

contract init {
        address owner;
        function init()
            owner = msg.sender;

        function send() public payable{


attached is the image of code and the console

  • It doesn't look like you asked a question here. Are you running into some issue? – Shawn Tabrizi Dec 26 '18 at 5:47
  • yes. it is not transferring the balance to owner – Suman Raj Dec 26 '18 at 5:50
  • i want to transfer the ether balance which is (100 Ether by default in remix) to the owner when the sender execute send function. – Suman Raj Dec 26 '18 at 5:57
  • Check my answer. The user needs to select how much Ether they will send. The transaction will not automatically choose an Ether amount, nor can you automatically have a contract transfer the entire balance of a user. The user must explicitly include how much they want to send as a part of the transaction's parameters. If you want to automate the transfer of the full balance of the user, you may be able to use a front end ux with web3.js to automatically figure out the total balance of the user, and input that as a part of the transaction to be signed. – Shawn Tabrizi Dec 26 '18 at 5:58
  • 1
    Think about how dangerous it would be if a contract could do that. I could trick you to call my function, and steal all your Ether. Actions like this should be, and are, explicit. – Shawn Tabrizi Dec 26 '18 at 6:17

Taking a better look at the screenshot you provided, you are not sending any value in your transaction, therefore nothing happens...

You need to make sure to set the value option when initiating the send transaction.

It should look like this: Image of a transaction while sending value

| improve this answer | |

If you want to transfer the entire balance of the contract to the owner of the contract, then you should replace msg.value with address(this).balance.

If the balance of the contract prior to calling function send is 0, then it will indeed transfer the entire balance of the contract to the owner of the contract.

Otherwise, you are transferring to the owner of the contract the exact amount of ether that the caller of function send has just transferred to the contract.

| improve this answer | |

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.