簡體   English   中英

查詢 Polkadot js 以獲取 Substrate 存儲密鑰的正確方法是什么?

[英]What is the right way to query Polkadot js for a Substrate storage key?

我試圖從 Substrate 存儲中提取一個大數組,當通過 node.js 查詢時,我得到“無法解碼索引 0 上的 Vec 源太大”。

所以切換到 curl 和 JSON RPC 接口,我想檢查我是否可以在 node.js 中正確生成哈希,然后使用它們直接通過 RPC 進行查詢。

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

(嘗試關注Shawn 的 RPC 頁面),我得到:

0x845f1811116060262abe72f228571eca

但肖恩列出的答案是:

0x50a63a871aced22e88ee6466fe5aa5d9

在 json RPC 調用中使用 Shawn 的值給出了預期的結果:

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}

如果我直接查詢sudo.key ,我會得到預期的答案:

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

那么什么給呢?

Jaco 在聊天中解決了這個問題。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM