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...

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


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 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.