代码之家  ›  专栏  ›  技术社区  ›  Eddy

Solidity函数不向W3返回哈希数组

  •  0
  • Eddy  · 技术社区  · 8 年前

    我有一个 solidity Remix 而且效果很好。

    在开发中,我从 nodejs 但出于某种原因 [object Object] 它不包含哈希数组。

    web3 提供程序不是 Ethereum 但是 Quorum 7nodes example.

    这就是 功能:

    function getHashs(string id) public view returns (bytes32[]) {
        bytes32[] memory stringsToHash = getStrings(id);
        bytes32[] memory hashes = new bytes32[](5);
    
        for(uint i=0; i<=stringsToHash.length-1; i++) {
            bytes32 str = seeds[i];
            bytes32 hash = sha256(abi.encodePacked(seed));
            hashes[i] = hash;
        }
    
        return hashes;
    }
    

    这就是 w3 代码:

    function getHashes(id, contract, fromAccount, privateForNode) {
    
       return new Promise(function(resolve, reject) {
    
           contract.methods.getHashs(id).send({from: fromAccount, gas: 150000000, privateFor: [privateForNode]})
           .then(hashes => {
               console.log("got hashes from node === ");
               console.log(hashes[0]); // this is 'undefined'
              resolve(hashes);
           },
           (error) => {
               reject(error);
           }).catch((err) => {
                reject(err);
           });
    
       })
       .catch((err) => {
          reject(err);
       });
    }
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   user94559    8 年前

    而不是 .send(...) .call(...) . 前者向网络广播一个事务,结果是一个事务散列,并最终(一旦事务被挖掘)一个事务收据。交易没有智能合约的返回值。

    。调用(…) 用于 view 功能。它在本地(仅在连接到的节点上)计算函数调用的结果,而不发送事务,并将结果返回给您。区块链中没有状态变化,因为没有广播任何事务。 call

    推荐文章