Skip to content

Instantly share code, notes, and snippets.

@bitcoinwarrior1
Last active August 18, 2021 04:16
Show Gist options
  • Save bitcoinwarrior1/840b77de13ef897f6683f47d3d6466f8 to your computer and use it in GitHub Desktop.
Save bitcoinwarrior1/840b77de13ef897f6683f47d3d6466f8 to your computer and use it in GitHub Desktop.
Getting balances from a substrate node using RPC
// UPDATED THANK YOU @al3mart
util_crypto.xxhashAsHex("System", 128)
> "0x26aa394eea5630e07c48ae0c9558cef7"
util_crypto.xxhashAsHex("Account", 128)
> "0xb99d880ec681799c0cf30e8886371da9"
// https://westend.subscan.io/account/5ENpP27BrVdJTdUfY6djmcw3d3xEJ6NzSUU52CCPmGpMrdEY
util_crypto.blake2AsHex(keyring.decodeAddress("5ENpP27BrVdJTdUfY6djmcw3d3xEJ6NzSUU52CCPmGpMrdEY"), 128)
> "0xbb08f275d00049b315666c2c44130a10"
// Get the account ID from the pubkey
subkey inspect 5ENpP27BrVdJTdUfY6djmcw3d3xEJ6NzSUU52CCPmGpMrdEY
> Account ID: 0x6648d7f3382690650c681aba1b993cd11e54deb4df21a3a18c3e2177de9f7342
// System + Account + hash_of_key + raw_key
0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9bb08f275d00049b315666c2c44130a106648d7f3382690650c681aba1b993cd11e54deb4df21a3a18c3e2177de9f7342
curl -H "Content-Type: application/json" -d '{"id":1,"jsonrpc":"2.0","method":"state_getStorage","params":["0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9bb08f275d00049b315666c2c44130a106648d7f3382690650c681aba1b993cd11e54deb4df21a3a18c3e2177de9f7342"]}' https://westend-rpc.polkadot.io/
> {"jsonrpc":"2.0","result":"0xda000000000000000100000000000000f86be7c3bd31870300000000000000008094d54ee900000000000000000000000000000000000000000000000000000000000000000000000000000000000000","id":1}
// SKALE decode the raw output
// https://www.shawntabrizi.com/substrate-js-utilities/codec/
// custom type:
{ "Balances": "(u64, u64, u64, u64, u64)" }
// decoded output
> [218,1,"0x038731bdc3e76bf8",0,1002050000000]
// 218 == the account nonce
// 1 (maybe the account index?)
// 0x038731bdc3e76bf8 == 254226595075025912 == the account total balance
// 0 which probably equals the locked balance
// 1002050000000 == the reserved balance
@daniel-flex
Copy link

^^ yeah boi

@bitcoinwarrior1
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment