title: How to read a hash value and get the corresponding AccountId from Substrate using RPC call?
body: <p>I have a substrate node up and running with storage item as: <code>value(Hash): Option&lt;AccountId&gt;</code>. My aim is to provide the hash value (say, <code>0x0000000000000000000000000000000000000000000000000000000000000001</code> and get the corresponding account id in return).</p>
  
  <p>When I do this through the UI, I get the following:
  <a href="https://i.stack.imgur.com/mSQg2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mSQg2.png" alt="enter image description here"></a></p>
  
  <p>I want to perform the same task via RPC calls. After going through <a href="https://www.shawntabrizi.com/substrate/querying-substrate-storage-via-rpc/" rel="nofollow noreferrer">this</a> blog post, I realized that my case would be to read the <code>StorageMaps</code> and so I began with running a few queries. If I am not wrong, the module is <code>Substratekitties</code> and the storage item is <code>value</code>. The mapping would be <code>value</code> to <code>AccountId</code>.</p>
  
  <p>I ran the first two calls:</p>
  
  <pre><code>util_crypto.xxhashAsHex("Substratekitties", 128)
  "0xe4a154b5ba85d6072b187ee66e4fef05"
  util_crypto.xxhashAsHex("Value", 128)
  "0x6b2f21989c43cc4e06ac1ad3e2027000"
  </code></pre>
  
  <p>But I am confused in the third call encoding: encoding the file sha256 hash. How to do that?
  Running <code>util_crypto.blake2AsHex("0000000000000000000000000000000000000000000000000000000000000001", 256)
  "0x16821de47d8b3b0fa4ca43e5db1028d75207cbd1c379a4738144972b105355aa"
  </code> won't work and is not working either.</p>
  
  <p>By not working I mean, I get the "null" values when executing this query.
  This is the storage struct:</p>
  
  <pre><code>use frame_support::{decl_module, decl_storage, dispatch::result::Result, ensure, StorageMap};
  use frame_system::ensure_signed;
  use sp_runtime::DispatchError;
  
  // pub trait Trait: balances::Trait {}
  pub trait Trait: pallet_balances::Trait {}
  
  decl_storage! {
      trait Store for Module&lt;T: Trait&gt; as KittyStorage {
          // Value: map T::Hash =&gt; Option&lt;T::AccountId&gt;;
          // TODO: check whether this is the appropriate datatype(hash).
          Value: map hasher(blake2_256) T::Hash =&gt; Option&lt;T::AccountId&gt;;
          // Balances: map hasher(blake2_256) (T::AssetId, T::AccountId) =&gt; T::Balance;
      }
  }
  
  decl_module! {
      pub struct Module&lt;T: Trait&gt; for enum Call where origin: T::Origin {
          fn set_value(origin, value: T::Hash) -&gt; Result&lt;(), DispatchError&gt; {
              let sender = ensure_signed(origin)?;
              ensure!(!&lt;Value&lt;T&gt;&gt;::contains_key(value), "key already exists");
              &lt;Value&lt;T&gt;&gt;::insert(value, sender);
              Ok(())
          }
      }
  }
  
  </code></pre>
  
  <p>Update:
  My literal query:</p>
  
  <pre><code>curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getStorage", "params": ["0x3fd011a1ea758d2e1b46ed3cec43fc86b2f21989c43cc4e06ac1ad3e2027000d3585436436a2253c5163fa0cfe54a648fa533ef32ea10dbd966ac438af77b71"]}' http://localhost:9933/
  </code></pre>
  
  <p>Hex queries:</p>
  
  <pre><code>util_crypto.xxhashAsHex("KittyStorage", 128)
  "0xe3fd011a1ea758d2e1b46ed3cec43fc8"
  util_crypto.xxhashAsHex("Value", 128)
  "0x6b2f21989c43cc4e06ac1ad3e2027000"
  util_crypto.blake2AsHex("0x0000000000000000000000000000000000000000000000000000000000001234")
  
  "0xd3585436436a2253c5163fa0cfe54a648fa533ef32ea10dbd966ac438af77b71"
  </code></pre>