当我传递我的智能合约函数的数组时,它给我的错误说“无效函数的参数数量无效”为什么?

问题描述 投票:0回答:1

我有一个名为ChainList.sol的智能合约文件,其中有一个名为“getArticlesForSale”的函数(参见下面的代码),它返回一个索引数组。我还有一个app.js文件,我使用promise调用此函数(参见下面的代码)。但是在控制台中,它给了我一个错误,上面写着“对于一个可靠性函数的参数无效”。在app.js文件(第二个代码)中,它正在运行“catch”部分并给出错误。

在我的合同中,我尝试将uint转换为“uint32”,假设javascript无法读取大整数,即“uint256”。但仍然得到这个错误。

// ChainList.sol file
// fetch and return all article IDs which are still for sale
  function getArticlesForSale() public view returns (uint[] memory) {
    // prepare an output array
    uint[] memory articleIds = new uint[](articleCounter);

    uint numberOfArticlesForSale = 0;
    // iterate over all the articles
    for (uint i = 1; i <= articleCounter; i++) {
      if (articles[i].buyer == address(0)) {
        articleIds[numberOfArticlesForSale] = articles[i].id;
        numberOfArticlesForSale++;
      }
    }

    // copying article ids into smaller forSale array
    uint[] memory forSale = new uint[](numberOfArticlesForSale);

    for (uint j = 0; j < numberOfArticlesForSale; j++) {
      forSale[j] = articleIds[j];
    }

    return forSale;
  }
// app.js file, interacting with my smart contract
App.contracts.ChainList.deployed().then(function(instance){
      chainListInstance = instance;
      return instance.getArticlesForSale();
    }).then(function(articleIds){

      // retrieve the article placeholder and clear it
      $('#articlesRow').empty();

      for (var i = 0; i < articleIds.length; i++) {
        var articleId = articleIds[i];
        chainListInstance.articles(articleId.toNumber()).then(function(article){
          // 0 is id, 1 is seller, 3 is name, 4 is description, 5 is price
          App.displayArticle(article[0], article[1], article[3], article[4], article[5]);
        });
      }

      App.loading = false;

    }).catch(function(err){
      console.error(err.message);
      App.loading = false;
    });

任何人都可以告诉我如何将一系列可靠性传递给javascript承诺。

blockchain solidity web3js
1个回答
1
投票

它现在正在运作。

  • 删除“build”文件夹。
  • 重新编译和迁移。

它现在应该工作。在我的情况下,我实际上忘了在一个语句中删除注释,这就是我收到此错误的原因。

© www.soinside.com 2019 - 2024. All rights reserved.