【问题标题】:Solidity unexpected responseSolidity 意外响应
【发布时间】:2020-03-18 23:13:46
【问题描述】:

我在为投票区块链创建solidity 类和ethers.js 接口时收到solidity unexpected response

这里是solidity函数

function addVoter(string memory _email) public returns (string memory) {
  return string('test');

  string memory key = random(_email);
  require(emailExists[key] == false);
  emailExists[key] = true;
  voters[key] = Voter({auth_code:key, authorized:true, candidate_id:0, email:_email, voted:false, voter_address:msg.sender});

  return key;
}

该函数将创建一个新的“选民”结构并为其分配一个随机数。

为了测试函数,在函数的开头放置了一个 return。

返回应该是系统响应。

所以我希望得到包含"test" 字符串的东西。 相反,我得到如下内容:

{ 哈希:'0x2c9a61d3e903d706ca829d009d4fdd9f4c2972f17e7b0fb5e1c65b9a0f73436d', 块哈希:'0x690948bea16c079b1ba33a0c79aa76e987b828e92aebacc477ec6f6a9152416e', 区块编号:266, 交易指数:0, 确认:1, 来自:'0x6002D48140d30B26C0B8A7B77D7Fa11A41a61a9F', gasPrice: BigNumber { _hex: '0x4a817c800' }, gasLimit: BigNumber { _hex: '0x5a53' }, 至:'0xaa0E1b62f1de3fdEC6474FFb78714b18b5477e4b', 值:BigNumber { _hex:'0x0' }, 随机数:227, 数据:'0xaca84892000000000000000000000000000000000000...', r: '0xe9aef9a334b805240a4450845a640153292578b122ce487604ed3e4f135f70a3', s: '0x0eddc482b19115e983018e4b9fe1541b325096ff61c581c559cc54f153527ae8', 五:27, 创建:空, 原始:'0xf8ca81e38504a817c800825a5394aa0e1b62f...', 网络ID:0, 等待:[功能] }

以上是使用 ethers.js 构建以下函数的结果

contract.addVoter('some_email').then((par) => {
    registered = par;
    console.log(par);
});

问题是,我们在代码中做错了什么还是我们误解了什么?

【问题讨论】:

    标签: blockchain ethereum solidity


    【解决方案1】:
    1. 在智能合约中,将该值存储在一个变量中,并在交易确认后使用call 获取该值。

    2. 使用event记录值

    【讨论】:

    • 好的,但是我该怎么做呢?文档让我很困惑。
    • 好的,我找到了实现你提出的store和call方法的方法。
    猜你喜欢
    • 2018-05-16
    • 2014-09-21
    • 2012-11-03
    • 2019-05-08
    • 2019-11-12
    • 1970-01-01
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多