首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将bytes32推送到数组

将bytes32推送到数组
EN

Ethereum用户
提问于 2018-01-23 18:05:42
回答 1查看 588关注 0票数 0

我试图将一个bytes32推到一个数组中,但是它仍然是空的。

这是我代码的一部分:

代码语言:javascript
复制
contract Voting {
    bytes32[] public encryptedVotes;
    bytes32[] public candidateList;
    address[] public pollingStationList;
    address public owner;
    function Voting(bytes32[] _candidateList, address[] _pollingStationList) public {
        candidateList = _candidateList;
        pollingStationList = _pollingStationList;
        owner = msg.sender;
    }

    function vote(bytes32 encryptedVote) public {
        encryptedVotes.push(encryptedVote);
    }

    function getEncryptedVotes() view public returns (bytes32[]) {
        return encryptedVotes;
    }
}

不要介意代码的“加密”部分,它是更多逻辑的一部分。

问题在于“投票”的功能。当我用web3调用它"contractInstance.vote.call("a值“)”时,它返回[],但不改变状态。调用getEncryptedVotes返回[]。

我没有看到围绕bytes32的一些逻辑吗?提前感谢!

EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-01-23 18:24:34

你的问题在于你怎么称呼它。使用契约函数的".call“不会创建事务,它将对该函数执行只读调用。这用于常量/视图函数。因此,当您调用contractInstance.vote.call("a value")时,它将从链上运行该函数,而不会更新状态。您应该能够只调用constractInstance.vote("a value"),它实际上将更新契约的状态。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/37256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档