Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum Solidity函数不返回预期数据_Ethereum_Solidity - Fatal编程技术网

Ethereum Solidity函数不返回预期数据

Ethereum Solidity函数不返回预期数据,ethereum,solidity,Ethereum,Solidity,我有一份具有以下职能的合同: function supply () constant returns (uint sup) { sup = 100; return sup; } 运行 var token = web3.eth.contract(contractAbi).at(contractAddress); token.supply.call() 返回: { [String: '0'] s: 1, e: 0, c: [ 0 ] } 这里怎么了?我在合同中的所

我有一份具有以下职能的合同:

 function supply () constant returns (uint sup) {
    sup = 100;
    return sup;
  }
运行

  var token = web3.eth.contract(contractAbi).at(contractAddress);
  token.supply.call()
返回:

{ [String: '0'] s: 1, e: 0, c: [ 0 ] }
这里怎么了?我在合同中的所有职能都发生了这种情况

谢谢

您得到的是“BigNumber”格式,uint(256)总是这样,因为这些数字比Javascript实际能够处理的要大

考虑使用返回值格式。此处的示例/文档:

松露风格(承诺)

回调样式

token.supply.call(function(error, returned) {
  if(!error) {
    console.log(returned.toString(10));
  } else {
    console.error(error);
});
上述示例可能会失去一些精度。从上面链接的文档

建议您始终保持平衡,只需变换 当向用户演示时,它将显示给其他单元:

希望能有帮助

更新:

合同在混音中对我有效,因此我将关注您调用函数的方式,并等待响应


谢谢Rob,你能理解为什么我没有得到预期的100分,而是得到了0分吗?你是在geth、truffle控制台还是其他什么地方?你在等电话回电吗?谢谢,罗布,事情就这样解决了。我正在使用块菌和testrpc,并使用exec来测试东西。我现在一切正常,我没有在每次新部署时更新合同地址。
token.supply.call(function(error, returned) {
  if(!error) {
    console.log(returned.toString(10));
  } else {
    console.error(error);
});