从Solidity智能合约填充Reactjs数组列表

时间:2019-03-20 15:13:10

标签: javascript reactjs ethereum solidity

每次添加新文件时,我都试图更新Reactjs数组列表。我的智能合约文件的一部分是

struct file {
        string description;
        string hash;
    }

    uint public FileCounts = 0;
    uint public FileId = 0;
    mapping (uint => file) files;
    event _fileCreated(uint indexed id);
    event _fileUpdated(uint indexed id);

    function getFile(uint id) external constant returns (string, string) {
      file storage F = files[id];

      return (F.description, F.hash);
    }

    function FileCount() public view returns (uint) {
    return FileCounts;
    }

这是反应部分:

  class FilesIndex extends Component {

     static async getInitialProps(props) {
      const { address } = props.query;
      const fileCounts = await auction.methods.FileCounts().call();

      const requests = await Promise.all(
        Array(fileCounts).fill().map((element, index) => {
          return auction.methods.getFile(index).call();
        })
      );

      return { address, requests, fileCounts };
    }

我无法从智能合约中获取数据!文件计数不返回任何内容

我该如何解决这个问题?

0 个答案:

没有答案