gpt4 book ai didi

ethereum - 获取公共(public)数组变量的长度(getter)

转载 作者:行者123 更新时间:2023-12-02 09:11:30 26 4
gpt4 key购买 nike

我正在尝试从另一个联系人处获取数组的长度。怎么办?

contract Lottery {
unint[] public bets;
}

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

最佳答案

您必须在源合约中将所需的长度公开为函数返回值。

调用合约将需要 ABI 和合约地址,这是通过下面的状态变量和构造函数处理的。

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();
}
}

希望有帮助。

关于ethereum - 获取公共(public)数组变量的长度(getter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43016011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com