1

I am trying to pull a large array from Substrate storage, and when querying via node.js I get "Unable to decode Vec on index 0 Source is too large".

So switching to curl and the JSON RPC interface, I wanted to check I could generate hashes correctly in node.js and then use them to query via RPC directly. Trying

const { xxhashAsHex, blake2AsHex } = require('@polkadot/util-crypto');
const { stringToU8a } = require('@polkadot/util');
...
console.log(xxhashAsHex(stringToU8a("Sudo key"), 128));

(trying to follow Shawn's RPC page), I get:

0x845f1811116060262abe72f228571eca

But Shawn lists the answer as:

0x50a63a871aced22e88ee6466fe5aa5d9

Using Shawn's value in a json RPC call gives the expected result:

curl -H "Content-Type: application/json" -d 
  '{"id":1,"jsonrpc":"2.0","method":"state_getStorage",
    "params":["0x50a63a871aced22e88ee6466fe5aa5d9"]}'
    http://127.0.0.1:9933/ 
> {"jsonrpc":"2.0",
 "result":"0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d",
  "id":1}

If I query sudo.key directly, I do get the expected answer:

console.log((await api.query.sudo.key()).toHex());
> 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d

So what gives?

4

1 回答 1

3

Jaco 在聊天中解决了这个问题。

我需要的是查询xxhashAsHex(stringToU8a("Sudo Key"), 128)(注意大写 K)。

于 2019-11-25T15:06:41.793 回答