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]);

    }
}
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?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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