如何从以太坊区块链检索数据
How can I retrieve the data from Ethereum Blockchain
我是区块链新手,node.js。如何使用节点获取方法从以太坊区块链检索数据。
是否可以找回原始保存的数据?
根据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
我是区块链新手,node.js。如何使用节点获取方法从以太坊区块链检索数据。
是否可以找回原始保存的数据?
根据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