如何获取智能合约存储数据?
3 个回答
- 投票数
-
- 2019-05-06
我找到了解决方法!
对我来说
function httpGet() { let xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", 'https://alphanet-node.tzscan.io/chains/main/blocks/head/context/contracts/<CONTRACT_ADDRESS>/storage', false ); // false for synchronous request xmlHttp.send( null ); return JSON.parse(xmlHttp.responseText) }
它返回带有存储数据的JSON对象.
I found the solution!
For me it:
function httpGet() { let xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", 'https://alphanet-node.tzscan.io/chains/main/blocks/head/context/contracts/<CONTRACT_ADDRESS>/storage', false ); // false for synchronous request xmlHttp.send( null ); return JSON.parse(xmlHttp.responseText) }
It returns JSON object with storage data.
-
- 2020-03-15
Tzscan已加入Dune网络,API可能会发生巨大变化,这将破坏您的应用程序. 为什么不使用Taquito?它简单而优雅,并且与您的应用程序捆绑在一起的软件包,如果有更新,它将不会中断.
import { Tezos } from "@taquito/taquito"; [...] Tezos.setProvider({...}); const contract = await Tezos.contract.at(contractAddress) const storage = await contract.storage();
就是这样,除了可以轻松访问存储之外,您还可以在Maps/BigMaps中搜索键/值:)
Tzscan has joined the Dune network and APIs can change quite dramatically, which will break your app. Why not using Taquito? It is simple and elegant and the package being bundled with your app, it won't break if there is an update.
import { Tezos } from "@taquito/taquito"; [...] Tezos.setProvider({...}); const contract = await Tezos.contract.at(contractAddress) const storage = await contract.storage();
And that's it, in addition of having an easy access to the storage, you can also search your Maps/BigMaps for keys/values :)
-
- 2020-03-30
您可以使用对我有用的eztz函数
storage = await eztz.contract.storage(contractAddress);
输出将为JSON格式,您可以将输出字符串化为
JSON.stringify(storage);
希望对您有所帮助.祝你好运...
You can use eztz function as that worked for me,
storage = await eztz.contract.storage(contractAddress);
The output will be in JSON format, you can stringify the output as,
JSON.stringify(storage);
Hope that will help you. Good luck...
我尝试获取智能合约存储数据:
但出现错误:
TypeError: contract.storage is not a function
我也试图在tzscan上找到用于此的API方法.
有接收存储数据的主意吗?
预先感谢您的帮助