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,300 points
325 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,910 points
394 views
+1 vote
1 answer
+4 votes
4 answers

What are the implementations of IBM blockchain?

IBM is an open source community of ...READ MORE

answered Mar 29, 2018 in Blockchain by Christine
• 15,830 points
186 views
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,830 points
611 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
3,636 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,150 points
498 views
0 votes
1 answer
0 votes
1 answer