如何从js访问智能合约的公共地址?

时间:2018-08-08 17:53:43

标签: javascript smartcontracts truffle

我拥有

所有者的公共地址
address public owner;

我想在js函数中访问它。我试图从已部署合同的实例中调用它,但显示类似

 ƒ () {
       var instance = this;
       var args = Array.prototype.slice.call(arguments);
       var tx_params = {};
       var last_arg = args[args.length - 1];

       // It's only tx_params …

在控制台中。

1 个答案:

答案 0 :(得分:1)

假设您的合同名称为Cat,并且其中有address public owner;行。

以下是您在部署合同后可以在$ truffle console终端中使用的代码:

c = Cat.at("put Cat contract address here")
c.owner.call()

仅此而已。

相关问题