0

this is very basic but i just want to test the transfer function. I load the contract with the constructor with 1 eth, then when i click the transfer function 0 wei is transferred. I understand this contract isn't very secure or good. But I just want to get this simple transfer out to an address to demonstrate what can be done.

My below code is as follows:

pragma solidity ^0.4.20;

contract Escrow {

    address public a;
    address public b;
    uint balance;



    constructor() public payable {
        a = msg.sender;
        b = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c;
        balance = address(this).balance;

    }

    function payoutToSeller() payable public returns(bool) {
        if (msg.sender == a) {
            b.transfer(balance);
            }
        }

     function getData() public constant returns (uint) {
         return balance;
     }

}
3
  • you got an issue or what? I just tried it on remix and it works well, remember to send the eth when you create the instance of the contract
    – mirg
    Apr 24 '18 at 12:23
  • it's not transferring any wei in the contract, the recipient does not receive anything. Apr 24 '18 at 12:24
  • 1
    because when you create the instance you have to set the value since the constructor is payable. If not the default would be 0.
    – mirg
    Apr 24 '18 at 12:27
-1

It works well, the balance of the contract is transfered.

Your logical mistake is that you don't update the balance after transfering, so it should be

    if (msg.sender == a) {
        b.transfer(balance);
        balance = 0;
        }
    }

You were probably calling payoutToSeller then checking the balance with getData to see if it was zero.

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.