根据Web3 API文档,检索合同实例和调用方法的方法是:
的 1.合同定义 强>
var MyContract = web3.eth.contract(abi);
的 2.在地址获取合同实例 强>
var myContractInstance = MyContract .at('0x**********');
的 3.执行呼叫 强>
var owner = myContractInstance .owner.call();
的 完整代码: 强>
var abi = [ { "constant": true, "inputs": [], "name": "owner", "outputs": [ { "name": "", "type": "address" } ], "payable": false, "type": "function" }, { "inputs": [], "payable": false, "type": "constructor" } ]; var MyContract = web3.eth.contract(abi); // initiate contract for an address var myContractInstance = MyContract .at('0xa07ddaff6d8b7aabf91ac6f82bf89455eb9784f4'); // call constant function (synchronous way) var owner = myContractInstance .owner.call(); console.log("owner="+owner);
的 工作良好: 强>
owner=0x13a0674c16f6a5789bff26188c63422a764d9a39