> ## Documentation Index
> Fetch the complete documentation index at: https://docs.near.org/llms.txt
> Use this file to discover all available pages before exploring further.

# View Contract State

> Returns the state (key-value pairs) of a contract based on the key prefix.



## OpenAPI

````yaml /openapi.json post /EXPERIMENTAL_view_state
openapi: 3.0.0
info:
  title: NEAR Protocol JSON RPC API
  version: 1.2.3
servers:
  - url: https://rpc.mainnet.near.org
    description: Mainnet
  - url: https://rpc.testnet.near.org
    description: Testnet
security: []
paths:
  /EXPERIMENTAL_view_state:
    post:
      summary: View Contract State
      description: >-
        Returns the state (key-value pairs) of a contract based on the key
        prefix.
      operationId: EXPERIMENTAL_view_state
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JsonRpcRequest_for_EXPERIMENTAL_view_state'
        required: true
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/JsonRpcResponse_for_RpcViewStateResponse_and_RpcViewStateError
components:
  schemas:
    JsonRpcRequest_for_EXPERIMENTAL_view_state:
      properties:
        id:
          type: string
        jsonrpc:
          type: string
        method:
          enum:
            - EXPERIMENTAL_view_state
          type: string
        params:
          $ref: '#/components/schemas/RpcViewStateRequest'
      required:
        - jsonrpc
        - id
        - params
        - method
      title: JsonRpcRequest_for_EXPERIMENTAL_view_state
      type: object
    JsonRpcResponse_for_RpcViewStateResponse_and_RpcViewStateError:
      oneOf:
        - $ref: >-
            #/components/schemas/JsonRpcResponse_for_RpcViewStateResponse_and_RpcViewStateError_variant0
        - $ref: >-
            #/components/schemas/JsonRpcResponse_for_RpcViewStateResponse_and_RpcViewStateError_variant1
      properties:
        id:
          type: string
        jsonrpc:
          type: string
      required:
        - jsonrpc
        - id
      title: JsonRpcResponse_for_RpcViewStateResponse_and_RpcViewStateError
      type: object
    RpcViewStateRequest:
      oneOf:
        - $ref: '#/components/schemas/RpcViewStateRequest_variant0'
        - $ref: '#/components/schemas/RpcViewStateRequest_variant1'
        - $ref: '#/components/schemas/RpcViewStateRequest_variant2'
      properties:
        account_id:
          $ref: '#/components/schemas/AccountId'
        include_proof:
          default: false
          type: boolean
        prefix_base64:
          $ref: '#/components/schemas/StoreKey'
      required:
        - account_id
        - prefix_base64
      title: RpcViewStateRequest
      type: object
    JsonRpcResponse_for_RpcViewStateResponse_and_RpcViewStateError_variant0:
      properties:
        result:
          $ref: '#/components/schemas/RpcViewStateResponse'
      required:
        - result
      type: object
    JsonRpcResponse_for_RpcViewStateResponse_and_RpcViewStateError_variant1:
      properties:
        error:
          $ref: '#/components/schemas/ErrorWrapper_for_RpcViewStateError'
      required:
        - error
      type: object
    RpcViewStateRequest_variant0:
      properties:
        block_id:
          $ref: '#/components/schemas/BlockId'
      required:
        - block_id
      type: object
    RpcViewStateRequest_variant1:
      properties:
        finality:
          $ref: '#/components/schemas/Finality'
      required:
        - finality
      type: object
    RpcViewStateRequest_variant2:
      properties:
        sync_checkpoint:
          $ref: '#/components/schemas/SyncCheckpoint'
      required:
        - sync_checkpoint
      type: object
    AccountId:
      description: >-
        NEAR Account Identifier.


        This is a unique, syntactically valid, human-readable account identifier
        on the NEAR network.


        [See the crate-level docs for information about
        validation.](index.html#account-id-rules)


        Also see [Error kind precedence](AccountId#error-kind-precedence).


        ## Examples


        ```

        use near_account_id::AccountId;


        let alice: AccountId = "alice.near".parse().unwrap();


        assert!("ƒelicia.near".parse::<AccountId>().is_err()); // (ƒ is not f)

        ```
      title: AccountId
      type: string
    StoreKey:
      description: >-
        This type is used to mark keys (arrays of bytes) that are queried from
        store.


        NOTE: Currently, this type is only used in the view_client and RPC to be
        able to transparently

        pretty-serialize the bytes arrays as base64-encoded strings (see
        `serialize.rs`).
      format: bytes
      type: string
    RpcViewStateResponse:
      description: Resulting state values for a view state query request
      properties:
        block_hash:
          $ref: '#/components/schemas/CryptoHash'
        block_height:
          format: uint64
          minimum: 0
          type: integer
        proof:
          items:
            type: string
          type: array
        values:
          items:
            $ref: '#/components/schemas/StateItem'
          type: array
      required:
        - values
        - block_height
        - block_hash
      type: object
    ErrorWrapper_for_RpcViewStateError:
      oneOf:
        - $ref: '#/components/schemas/ErrorWrapper_for_RpcViewStateError_variant0'
        - $ref: '#/components/schemas/ErrorWrapper_for_RpcViewStateError_variant1'
        - $ref: '#/components/schemas/ErrorWrapper_for_RpcViewStateError_variant2'
    BlockId:
      anyOf:
        - $ref: '#/components/schemas/BlockId_variant0'
        - $ref: '#/components/schemas/CryptoHash'
    Finality:
      description: Different types of finality.
      enum:
        - optimistic
        - near-final
        - final
      type: string
    SyncCheckpoint:
      enum:
        - genesis
        - earliest_available
      type: string
    CryptoHash:
      type: string
    StateItem:
      description: >-
        Item of the state, key and value are serialized in base64 and proof for
        inclusion of given state item.
      properties:
        key:
          $ref: '#/components/schemas/StoreKey'
        value:
          $ref: '#/components/schemas/StoreValue'
      required:
        - key
        - value
      type: object
    ErrorWrapper_for_RpcViewStateError_variant0:
      properties:
        cause:
          $ref: '#/components/schemas/RpcRequestValidationErrorKind'
        name:
          enum:
            - REQUEST_VALIDATION_ERROR
          type: string
      required:
        - name
        - cause
      type: object
    ErrorWrapper_for_RpcViewStateError_variant1:
      properties:
        cause:
          $ref: '#/components/schemas/RpcViewStateError'
        name:
          enum:
            - HANDLER_ERROR
          type: string
      required:
        - name
        - cause
      type: object
    ErrorWrapper_for_RpcViewStateError_variant2:
      properties:
        cause:
          $ref: '#/components/schemas/InternalError'
        name:
          enum:
            - INTERNAL_ERROR
          type: string
      required:
        - name
        - cause
      type: object
    BlockId_variant0:
      format: uint64
      minimum: 0
      title: block_height
      type: integer
    StoreValue:
      description: >-
        This type is used to mark values returned from store (arrays of bytes).


        NOTE: Currently, this type is only used in the view_client and RPC to be
        able to transparently

        pretty-serialize the bytes arrays as base64-encoded strings (see
        `serialize.rs`).
      format: bytes
      type: string
    RpcRequestValidationErrorKind:
      oneOf:
        - $ref: '#/components/schemas/RpcRequestValidationErrorKind_variant0'
        - $ref: '#/components/schemas/RpcRequestValidationErrorKind_variant1'
    RpcViewStateError:
      oneOf:
        - $ref: '#/components/schemas/RpcViewStateError_variant0'
        - $ref: '#/components/schemas/RpcViewStateError_variant1'
        - $ref: '#/components/schemas/RpcViewStateError_variant2'
        - $ref: '#/components/schemas/RpcViewStateError_variant3'
        - $ref: '#/components/schemas/RpcViewStateError_variant4'
    InternalError:
      oneOf:
        - $ref: '#/components/schemas/InternalError_variant0'
    RpcRequestValidationErrorKind_variant0:
      properties:
        info:
          properties:
            method_name:
              type: string
          required:
            - method_name
          type: object
        name:
          enum:
            - METHOD_NOT_FOUND
          type: string
      required:
        - name
        - info
      type: object
    RpcRequestValidationErrorKind_variant1:
      properties:
        info:
          properties:
            error_message:
              type: string
          required:
            - error_message
          type: object
        name:
          enum:
            - PARSE_ERROR
          type: string
      required:
        - name
        - info
      type: object
    RpcViewStateError_variant0:
      properties:
        info:
          properties:
            block_reference:
              $ref: '#/components/schemas/BlockReference'
          required:
            - block_reference
          type: object
        name:
          enum:
            - UNKNOWN_BLOCK
          type: string
      required:
        - name
        - info
      type: object
    RpcViewStateError_variant1:
      properties:
        info:
          properties:
            block_hash:
              $ref: '#/components/schemas/CryptoHash'
            block_height:
              format: uint64
              minimum: 0
              type: integer
            requested_account_id:
              $ref: '#/components/schemas/AccountId'
          required:
            - requested_account_id
            - block_height
            - block_hash
          type: object
        name:
          enum:
            - INVALID_ACCOUNT
          type: string
      required:
        - name
        - info
      type: object
    RpcViewStateError_variant2:
      properties:
        info:
          properties:
            block_hash:
              $ref: '#/components/schemas/CryptoHash'
            block_height:
              format: uint64
              minimum: 0
              type: integer
            requested_account_id:
              $ref: '#/components/schemas/AccountId'
          required:
            - requested_account_id
            - block_height
            - block_hash
          type: object
        name:
          enum:
            - UNKNOWN_ACCOUNT
          type: string
      required:
        - name
        - info
      type: object
    RpcViewStateError_variant3:
      properties:
        info:
          properties:
            block_hash:
              $ref: '#/components/schemas/CryptoHash'
            block_height:
              format: uint64
              minimum: 0
              type: integer
            contract_account_id:
              $ref: '#/components/schemas/AccountId'
          required:
            - contract_account_id
            - block_height
            - block_hash
          type: object
        name:
          enum:
            - TOO_LARGE_CONTRACT_STATE
          type: string
      required:
        - name
        - info
      type: object
    RpcViewStateError_variant4:
      properties:
        info:
          properties:
            error_message:
              type: string
          required:
            - error_message
          type: object
        name:
          enum:
            - INTERNAL_ERROR
          type: string
      required:
        - name
        - info
      type: object
    InternalError_variant0:
      properties:
        info:
          properties:
            error_message:
              type: string
          required:
            - error_message
          type: object
        name:
          enum:
            - INTERNAL_ERROR
          type: string
      required:
        - name
        - info
      type: object
    BlockReference:
      oneOf:
        - $ref: '#/components/schemas/BlockReference_variant0'
        - $ref: '#/components/schemas/BlockReference_variant1'
        - $ref: '#/components/schemas/BlockReference_variant2'
    BlockReference_variant0:
      additionalProperties: false
      properties:
        block_id:
          $ref: '#/components/schemas/BlockId'
      required:
        - block_id
      type: object
    BlockReference_variant1:
      additionalProperties: false
      properties:
        finality:
          $ref: '#/components/schemas/Finality'
      required:
        - finality
      type: object
    BlockReference_variant2:
      additionalProperties: false
      properties:
        sync_checkpoint:
          $ref: '#/components/schemas/SyncCheckpoint'
      required:
        - sync_checkpoint
      type: object

````