0

I have tested with eth.getStorageAt() and it shows what I think is 32 bytes of storage. But what is the point of this function? Are we meant to see unused space with it?

This is what I have:

> con
{
  abi: [{
  constant: true,
  inputs: [],
  name: "studentAge",
  outputs: [{...}],
  payable: false,
  stateMutability: "view",
  type: "function"
  }, {
  constant: false,
  inputs: [{...}],
  name: "setAge",
  outputs: [],
  payable: false,
  stateMutability: "nonpayable",
  type: "function"
  }, {
  anonymous: false,
  inputs: [{...}],
  name: "changedAge",
  type: "event"
 }],
 address: "0xa6b4017e8437ace3301f9751735e84836cfc0b21",
 transactionHash: null,
 allEvents: function(),
 changedAge: function(),
 setAge: function(),
 studentAge: function()
}
> eth.getStorageAt(con.address,0)
"0x000000000000000000000000000000000000000000000000000000000000002d"
> eth.getStorageAt(con.address,1)
"0x0000000000000000000000000000000000000000000000000000000000000000"
> 

Code:

pragma solidity ^0.4.18;
contract CollegeAdmin {
uint public studentAge=18;
event changedAge(uint age);
function setAge(uint age) public { 
studentAge = age;
changedAge(age);
}
}
8
  • It's just a tool to see the contents of a smart contract's storage. It might be useful in debugging scenarios, particularly to inspect private state variables.
    – user19510
    Feb 22, 2018 at 5:19
  • I guessed that was the purpose, but I have 2d in the storage - do I compare that to bytecode or something like that? Is the bytecode references by storageAt? Feb 22, 2018 at 5:29
  • Apparently the value that's stored in slot 0 in your contract's storage is 0x2d (45). Without knowing your code, I don't know what variable that is or why that's the value. I'm not sure what you're asking about in terms of bytecode... storageAt just reads storage at the specified slot.
    – user19510
    Feb 22, 2018 at 5:31
  • Code added - I also added an age using geth. Feb 22, 2018 at 5:33
  • studentAge should be in slot 0. Does that answer your question? If not, what question do you still have?
    – user19510
    Feb 22, 2018 at 5:52

0

Your Answer

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

Browse other questions tagged or ask your own question.