繁体   English   中英

为什么 truffle 控制台没有在 Solidity 智能合约中打印正确的变量?

[英]Why does the truffle console not print correct variable in solidity smart contract?

我是使用 Solidity 和 truffle 编写以太坊智能合约的初学者。 我做了一个简单的智能合约来部署,它设置了一个等于 1000000 的变量,如下所示:

pragma solidity >=0.4.22 <0.8.0;
contract CelesteToken{
uint256 public totalSupply;
  function ClesteToken()public{
    totalSupply = 1000000;
}
}

在松露控制台中,我使用了以下命令:

CelesteToken.deployed().then(function(i){token =i;})
token.totalSupply().then(function(s){totalSupply =s;})
totalSupply.toNumber()

但是,不是按照代码返回 1000000,而是返回 0。我不确定为什么会发生这种情况,有人可以帮忙吗?

你可以尝试更换

function ClesteToken()public{
    totalSupply = 1000000;
}

constructor () public {
    totalSupply = 1000000;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM