1

My code has a function which randomly select a subscriber from the list and all of the sum of the tokens should transfer to the winner account address. but unfortunately it is not working for me.

please somebody advice..

function WeeklyW1() public  view returns (address,uint, uint){

    uint randWinAddr = uint(block.blockhash(block.number - 1)) % subscriberListW1.length;
    winner = subscriberListW1[randWinAddr];

    for (uint i=0; i<subscriberListW1.length; i++) {
    uint value = (_balances[subscriberListW1[i]] * subscriberListW1.length) * 20/100;      
    uint value1 = ((_balances[subscriberListW1[i]] * subscriberListW1.length)
                    - (_balances[subscriberListW1[i]] * subscriberListW1.length) * 20/100);

    _balances[subscriberListW1[randWinAddr]] += value1 ;
    _balances[owner] += value;

    //these below are not working...
    owner.transfer(address(value).balance);
    winner.transfer(address(value1).balance);

    //It is just for verification purpose 
    return (winner,_balances[subscriberListW1[randWinAddr]],_balances[owner]);

    }
}
Aniket
  • 3,545
  • 2
  • 20
  • 42

1 Answers1

0

To get it working, you need to remove view from the function as only then your function will make changes in the state. If problem still persists, please share the error message.

For more details, see : What is the difference between a transaction and a call?

Aniket
  • 3,545
  • 2
  • 20
  • 42