---
title: getStorageAt
slug: api/getstorageat
createdAt: 2022-12-06T18:10:45.000Z
---

{
  "id": "78R7vVtRFb4_6OryasDW_",
  "data": {
    "url": "{{ENVIRONMENT}}",
    "method": "POST",
    "request": {
      "pathParameters": [],
      "queryParameters": [],
      "headerParameters": [
        {
          "name": "Content-Type",
          "type": "string",
          "example": "application/json",
          "description": ""
        }
      ],
      "bodyDataParameters": [
        {
          "name": "body",
          "type": "string",
          "example": "{\n\t\"jsonrpc\":\"2.0\", \n\t\"method\": \"eth_getStorageAt\", \n\t\"params\": [\n\t\t\"0x295a70b2de5e3953354a6a8344e616ed314d7251\", \n\t\t\"0x0\",\n\t\t\"latest\"\n\t], \n\t\"id\": 1\n}",
          "description": ""
        }
      ],
      "formDataParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "",
        "jsonExample": ""
      }
    ],
    "contentType": "application/json",
    "description": "<p>Returns the value from a storage position at a given address.</p>\n<p><strong>Parameters</strong></p>\n<p><code>DATA</code>, 20 Bytes - address of the storage.</p>\n<p><code>QUANTITY</code> - integer of the position in the storage.</p>\n<p><code>QUANTITY|TAG</code> - integer block number, or the string <code>\"latest\"</code>, <code>\"earliest\"</code> or <code>\"pending\"</code>, see the default block parameter</p>\n<p><strong>Returns</strong></p>\n<p><code>DATA</code> - the value at this storage position.</p>\n<p><strong>Example</strong></p>\n<p>Calculating the correct position depends on the storage to retrieve. Consider the following contract deployed at  0x295a70b2de5e3953354a6a8344e616ed314d7251 by address 0x391694e7e0b0cce554cb130d723a9d27458f9298.</p>\n<pre><code>contract Storage {\r\n    uint pos0;\r\n    mapping(address => uint) pos1;\r\n    \r\n    function Storage() {\r\n        pos0 = 1234;\r\n        pos1[msg.sender] = 5678;\r\n    }\r\n}\n</code></pre>\n<p>Retrieving the value of pos0 is straight forward:</p>\n<pre><code>curl -X POST --data '{\"jsonrpc\":\"2.0\", \"method\": \"eth_getStorageAt\", \"params\": [\"0x295a70b2de5e3953354a6a8344e616ed314d7251\", \"0x0\", \"latest\"], \"id\": 1}' {{ENVIRONMENT}}\r\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x00000000000000000000000000000000000000000000000000000000000004d2\"}\n</code></pre>\n<p>Retrieving an element of the map is harder. The position of an element in the map is calculated with:</p>\n<pre><code>keccack(LeftPad32(key, 0), LeftPad32(map position, 0))\n</code></pre>\n<p>This means to retrieve the storage on <code>pos1[\"0x391694e7e0b0cce554cb130d723a9d27458f9298\"]</code> we need to calculate the position with:</p>\n<pre><code>keccak(decodeHex(\"000000000000000000000000391694e7e0b0cce554cb130d723a9d27458f9298\" + \"0000000000000000000000000000000000000000000000000000000000000001\"))\n</code></pre>\n<p>The geth console which comes with the web3 library can be used to make the calculation:</p>\n<pre><code>> var key = \"000000000000000000000000391694e7e0b0cce554cb130d723a9d27458f9298\" + \"0000000000000000000000000000000000000000000000000000000000000001\"\r\nundefined\r\n> web3.sha3(key, {\"encoding\": \"hex\"})\r\n\"0x6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9\"\n</code></pre>",
    "examples": {
      "languages": [
        {
          "id": "example-0-curl",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url {{ENVIRONMENT}} \\\n     --header 'accept: application/json'"
        },
        {
          "id": "example-1-javascript",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"{{ENVIRONMENT}}\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "example-2-ruby",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"{{ENVIRONMENT}}\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "example-3-python",
          "language": "python",
          "label": "Python",
          "code": "import requests\n\nurl = \"{{ENVIRONMENT}}\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "example-0-curl"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": ""
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "type": "api-oas-v2",
  "children": [
    {
      "text": ""
    }
  ]
}