4

I try to get smart-contract storage data:

  eztz.node.setProvider('https://alphanet-node.tzscan.io')

  eztz.contract.watch(addr, 2, function(s){
    console.log("New storage", s);
  });

But got an error: TypeError: contract.storage is not a function

Also I tried to find API method for this on tzscan.

Any idea for receive storage data?

Thanks in advance for your help

3 Answers 3

2

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.

2

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 :)

1

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.