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

How to access public address of smart contract from js?

我有

所有者的 public 地址
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 …

在控制台中。

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

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

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

就是这样。