javascript - 如何从js访问智能合约的公共(public)地址?

标签 javascript smartcontracts truffle

我有所有者的公共(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()

仅此而已。

关于javascript - 如何从js访问智能合约的公共(public)地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51752866/

相关文章:

javascript - 如何在 javascript/truffle 中为每个测试创建新的 ethereum/solidity 合约

javascript - 我需要帮助使用 VS-2013 在服务器上部署我的 asp.net 网站

javascript - 如果 div 移动,Angularjs ng-repeat 不起作用

javascript - jQuery 复选框多选

ethereum - Solidity,成员 "transfer"在参数依赖后未找到或不可见

node.js - 从node.js调用已部署的智能合约

javascript - JSHint 选项默认值的完整列表?

blockchain - 如何在 Sui 区 block 链中定义 Move Error 类型

ethereum - 我可以将 truffle 项目配置为使用 .ipc 端点文件而不是以太坊 RPC 监听器吗?

ethereum - 部署失败 : project ID does not have access to archive state