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;
}
}
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;
}
}
You have to expose the length you want as a function return value in the source contract.
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();
}
}
Hope it helps.
getBetCount()
has 6 lines? I don't have VR 360 space dome code environment, I much prefer preserve screen real estate... –
Forego getter
for arrays but for primatives like uint256
we can just call them like in this: ethereum.stackexchange.com/questions/38317/… –
Ideogram public
array element but there is no "free" getter for the length
property of the array or the entire array. Passing entire arrays around should be avoided unless you really understand the implications. –
Bistort © 2022 - 2024 — McMap. All rights reserved.