Getting the length of public array variable getter

0 votes

I am trying to get the length of array from another contact. How?

contract Lottery {
    unint[] public bets;
}

contract CheckLottery {
    function CheckLottery() {
        Lottery.bets.length;
    }
}

Sep 24, 2018 in Blockchain by slayer
• 29,310 points
810 views

1 answer to this question.

0 votes

The calling contract will need the ABI and contract address, which is handled via the state var and constructor below.

pragma solidity ^0.4.8;

contract Lottery {

    uint[] public bets;

    function getBetCount()
        public 
        constant
        returns(uint betCount)
    {
        return bets.length;
    }
}

contract CheckLottery {

    Lottery l;

    function CheckLottery(address lottery) {
        l = Lottery(lottery);
    }

    function checkLottery() 
        public
        constant
        returns(uint count) 
    {
        return l.getBetCount();
    }
}
answered Sep 24, 2018 by digger
• 26,720 points

Related Questions In Blockchain

0 votes
2 answers

is there any way of getting all data in hyperledger fabric before we start the ledger

Hey, @Harinishree, You can also do one thing, ...READ MORE

answered Jun 4, 2020 in Blockchain by Gitika
• 65,890 points
829 views
0 votes
1 answer

Where does Hyperledger fabric store the public key and private key of the user?

It signs the transaction (eg. initiated by ...READ MORE

answered Mar 24 in Blockchain by Rahul
• 9,680 points
108 views
0 votes
1 answer

Where does Hyperledger fabric store the public key and private key of the user?

It signs the transaction with its private key ...READ MORE

answered Apr 11 in Blockchain by Rahul
• 9,680 points
117 views
+1 vote
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,106 views
0 votes
1 answer

Call contract methods with web3 from newly created account

In fact, we can't just send transactions ...READ MORE

answered Sep 25, 2018 in Blockchain by digger
• 26,720 points
5,229 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,210 points
889 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP