Cannot get contract data using storageAt()

givemecreditgivemecredit Member Posts: 20
edited July 2015 in web3-js
Hi all.

I just started learning about Ethereum development.

I am trying to display values from a contract using the dappsforbeginners tutorial as a reference. It was stated that i must "grab the contracts address" from the pending pane. There were several addresses listed, i'm guessing the "contracts address" is the one under "Creates" right?

e.g.
var contractAddress = "0x7AF909A9F6E5BFC0F3F45F25C13D300A86D186661D10FFF26AD5D32EE11328E0";

However, the following code returns nothing...

var contractString = JSON.stringify(web3.eth.storageAt(contractAddress));

Without JSON.stringify i am able to return an object (although i am unable to extract any useful info from it).

I looked at the API docs and i couldn't find the storageAt() method. Although i did find getStorageAt(). I assume getStorageAt() is out of date as it returns "TypeError: undefined is not a constructor". Is that right?

I'm confused. Any ideas what i can try?

Your advice would be greatly appreciated.

----------------------------------------

EDIT: I seem to get the error message "TypeError: undefined is not a constructor..." on many of the API calls.
Post edited by givemecredit on

Comments

  • KenKKenK Member Posts: 44 admin
    Dapps for beginners is a bit outdated I am afraid - generally most of the api calls won't work if you are running the latest version of alethzero.

    I am working on updated tutorials - but they take time. In the meantime here is the API documentation:

    https://github.com/ethereum/wiki/wiki/JavaScript-API

  • givemecreditgivemecredit Member Posts: 20
    Thanks Ken. Although i'm having issue getting any of the new api calls to work. I get "TypeError: undefined is not a constructor..." when i log it to the console. Is there something important that i'm missing?
  • linageelinagee Member Posts: 31 ✭✭

    Thanks Ken. Although i'm having issue getting any of the new api calls to work. I get "TypeError: undefined is not a constructor..." when i log it to the console. Is there something important that i'm missing?

    Did you pass two arguments to web3.eth.getStorageAt? Are you able to replicate the example shown here? https://github.com/ethereum/wiki/wiki/JavaScript-API#user-content-web3ethgetstorageat

    If not, a bit of code to replicate the error you were getting would help.
  • jesus666jesus666 Member Posts: 62 ✭✭
    getStorageAt needs the second argument which is the position index in contract storage memory that you want it to return.
  • givemecreditgivemecredit Member Posts: 20
    I'm aware of the second argument. Thanks. The issue appears to be more general as i get the same error on most API calls. May i ask...are you able to get the API calls working?

    I have been trying something like this...

    var contractString = web3.eth.getStorageAt("0x42629d656cc04c77100b1ac794fc66183701b9f8", 0);
    document.getElementById('contractString').innerText = contractString;

    BTW...if the documentation is outdated, any chance you could provide some kind of notice? Something big and bold perhaps?

    @linagee You mentioned on a different thread that you had "abandoned trying to get alethzero working". Can you elaborate on this please? Why have you abandoned alethzero? By "go-ethereum", you're talking about Mist/Geth right?

    Your assistance would be greatly appreciated. I really need something concrete to work with. If you give me something to learn, i can learn it. If you give me something which may become obsolete if the wind changes direction, then i'll give up and move on.



  • givemecreditgivemecredit Member Posts: 20
    edited August 2015
    does anyone have any info? I'm assuming some test dapps have been developed and deployed right? so how did you do it? what tools did you use? can someone please guide me through some kind of "hello world" app where i am able to write the to the block chain and the pull it back out. Thanks!
    Post edited by givemecredit on
  • sheehansheehan Member Posts: 2
    I'm trying to figure this out also.

    Normally, I'd write a getter in my contract and call that to return the value of a specific variable. Maybe that's all you need @givemecredit. See the SimpleStorage contract at https://github.com/iurimatias/embark-framework

    However, I'm trying to display all variable values in the contract. There may not be getter functions in my case.

    getStorageAt() works for number data types, but for strings, it's giving me the length of the string. How can I retrieve the actual value of the string?
  • sheehansheehan Member Posts: 2
    So to somewhat answer my own question, I've learned that in Solidity, public state variables all have accessors. https://github.com/ethereum/wiki/wiki/Solidity-Features#state-variable-accessors

    I'm still curious if it's possible to retrieve string values using the getStorageAt() function in the web3 api?
Sign In or Register to comment.