简体   繁体   English

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

[英]How to access public address of smart contract from js?

I have a public address of owner of 我有一个所有者的公共地址

address public owner;

I want to acess it inside a js function. 我想在js函数中访问它。 I tried to call it from the instance of the deployed contract but it shows something like 我试图从已部署合同的实例中调用它,但是它显示出类似以下内容

 ƒ () {
       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 …

in console. 在控制台中。

Assuming your contract name is Cat and you have address public owner; 假设您的合同名称为Cat并且您有address public owner; line inside it. 里面的线。

Here is the code that you can use in $ truffle console terminal after you deploy the contract: 部署合同后,可以在$ truffle console终端中使用以下代码:

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

That's all. 就这样。

暂无
暂无

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

相关问题 Web3js-部署后立即返回智能合约地址 - Web3js - Return smart contract address immediately after deployment 如何将智能合约返回的地址转换为可读的字符串? - How do I convert the address returned from my smart contract into a readable string? 映射动态数组从智能合约起反应,其值包括地址和字符串 - map dynamic array in react from a smart contract with values an address and a string 如何在 node.js 应用程序中使用 ethers.js contract.on() 监听来自智能合约的事件? - How do I listen to events from a smart contract using ethers.js contract.on() in a node.js application? 通过 web3.js 调用和访问智能合约功能? - Call and access smart contract function through web3.js? 如何在同一个 javascript 程序中部署和获取智能合约的地址 - How to deploy and get address of smart contract in same javascript program 如何在智能合约中将地址连接到午餐 function? | TypeError:无法读取未定义的属性(读取“连接”)ether.js - how can i connect an address to lunch a function in the smart contract ? | TypeError: Cannot read properties of undefined (reading 'connect') ether.js 如何使用 U64 参数从 js 调用 NEAR 智能合约? - How to call a NEAR smart contract from js with a U64 argument? 如何使用 nodejs 上的 Web3js 解码在以太坊上调用智能合约的响应 - How to decode response from calling smart contract on Ethereum using Web3js on nodejs 如何访问jQuery Smart Cart的公共方法? - How to access public methods of the jQuery Smart Cart?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM