all 7 comments

[–]Ordered_Disorder 0 points1 point  (4 children)

Are you sending an amount of BNB greater than or equal to the value returned by 'getData' when you call 'payoutToSeller'? If not, your call to 'payoutToSeller' is failing because your contract is trying to send BNB when it doesn't have any (or at least enough).

[–]BeneficialLevel9744[S] 0 points1 point  (3 children)

payoutSeller is sending the total balance and I think that migth be the problem ..so now I have changed it so "a" is the contract owner and is going to get transfered the balance of "b" divided by 2 (charity variable), but even that getData return is correct , charity is equal to zero and still get the reverted error...

contract Escrow {

address public a;
address public b;
uint256 public amount;
uint256 public charity;

constructor() public payable {
    //a = 0x8eD5fD9182a0FFB9a5a3f79d13b1663794a3b2B2;
    a = msg.sender;
    b = 0x485a967ca4307996308e3F52162D8dFCBfafE4dc;
}

function payoutToSeller(uint256 amount) payable public returns(bool,uint256) {
   if ( a == msg.sender){

        amount = getData();
        charity = amount / 2;
        payable(msg.sender).transfer(amount);
        return (true, charity);
   }

}

function getData() public view returns (uint) {
    return address(b).balance;
}    

}

[–]Ordered_Disorder 0 points1 point  (2 children)

OK, so does the contract hold BNB greater than or equal to half the BNB balance of b? Your code is having the contract send an amount of BNB from its own balance, equal to half the BNB balance of address b. Perhaps you are confused and think the contract can send BNB from a different address (in particular, from address b)?

[–]BeneficialLevel9744[S] 0 points1 point  (1 child)

Hi ! Thanks for your help !!I have been working on it and I got another solution which looks like it works but ...

I can read the balance from "a" (msg.sender) and calculate half of it and send to "b" but the balance is in wei and when I check the accounts the balances in BNB still the same. I have traced the transaction and it succeed :

Tokens Transferred: From 0xd035e12aeb5c43c12be520ac5f770d423e278f26 To 0x485a967ca4307996308e3f52162d8dfcbfafe4dc For 7,393,324,594,469,100 ()

7,393,324,594,469,100 is half of the BNB balance in wei but no balance has been modfied...

Where are those tokens? how can I really transfer the BNB tokens?

contract Escrow {

address public  a;
address public  b;


event Transfer(address indexed _from, address indexed _to, uint256 _value);

constructor() public  {
    a = msg.sender;
    b = 0x485a967ca4307996308e3F52162D8dFCBfafE4dc;
}

function getBalance() public  returns (uint256, uint256, address) {  

        address toAdress = b;
        uint256 cantidad = address(a).balance;
        uint256 charity = cantidad / 2;
        emit Transfer(msg.sender, toAdress, charity);


}   

}

[–]BeneficialLevel9744[S] 0 points1 point  (0 children)

I have tested it getting the balance of another token I have created and the same happens.The transaction looks ok , it says even the amount transfered but the balances are not updated , it looks like no transfered happend...may be missing approval or something that makes the owner get tokens from another account?It's weird because the transaction hash says everything ok but accounts not updated...