2

I know from https://github.com/near/near-cli#overview that I can call near state to view general details of an account, like this:

NEAR_ENV=mainnet near state root.near            
Account root.near
{
  amount: '517981340092537993206924239',
  block_hash: '6A4vsQqTjdQgKnWrHVURycSmehBMgtgg4GNemmjZUB6S',
  block_height: 64959783,
  code_hash: '11111111111111111111111111111111',
  locked: '0',
  storage_paid_at: 0,
  storage_usage: 13899,
  formattedAmount: '517.981340092537993206924239'
}

And I know that I can browse on the web at https://explorer.near.org/accounts/root.near

But how can I explore (either via a website or CLI) the contents of all of the on-chain data in an account's storage?

Ryan
  • 22,332
  • 31
  • 176
  • 357

1 Answers1

3

You can use the CLI's view-state command. An example of this could be:

  1. export NEAR_ENV=mainnet
  2. near view-state nft.nearvember-challenge.near --finality final

This will return key value pairs that are base64 encoded. You can loop through and decode these as you wish. For example, one of the key value pairs returned from this call is:

{
    key: 'A3YkAAAAAAAAAA==',
    value: 'ARgAAABORUFSdmVtYmVyIENoYWxsZW5nZSBORlQBNwAAAHRoYW5rIHlvdSBmb3IgcGFydGljaXBhdGluZyBpbiB0aGUgbmVhcnZlbWJlciBjaGFsbGVuZ2UBTwAAAGh0dHBzOi8vY2xvdWRmbGFyZS1pcGZzLmNvbS9pcGZzL1FtUEt6WnFIdnY1c2VCQ3hIdW5nNFpLRFlHS2QxOFozSzRmWWtHeTJTMjFOQVoAAWQAAAAAAAAAAAAAAAAAAA=='
  },

which, if base64 decoded, has a value of

NEARvember Challenge NFT7thank you for participating in the nearvember challengeOhttps://cloudflare-ipfs.com/ipfs/QmPKzZqHvv5seBCxHung4ZKDYGKd18Z3K4fYkGy2S21NAZd

Keep in mind that the CLI will only return state that's below a certain threshold. If the account's state is too large, it won't be viewable unless you configure and run your own node.

Ryan
  • 22,332
  • 31
  • 176
  • 357
Benjamin Kurrek
  • 1,044
  • 3
  • 14
  • Thank you so much, Benji! For my particular contract, I did unfortunately get the error `Error: [-32000] Server error: State of contract _____.near is too large to be viewed`. Is it really the case that the only way for me to view it is to run a node? I would have guessed that inherent to the idea of blockchain would be that the protocol would make all data easy to read, right? Thanks. – Ryan May 05 '22 at 18:28
  • 1
    I found https://docs.near.org/docs/api/rpc/contracts#view-contract-state which says "There is a limitation on default RPC nodes. You won't be able to get the contract state if it is too big. The default limit of for contract state is 50kb of state size. You're able to change the limits if you run your own RPC node with adjusted `trie_viewer_state_size_limit` value in `config.json`". – Ryan May 05 '22 at 18:34