> For the complete documentation index, see [llms.txt](https://docs.getblock.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getblock.io/api-reference/near-protocol-near/near_query_view_code.md).

# query(view\_code) - NEAR Protocol

This method returns the **smart contract code** deployed on a specific NEAR account. It provides the **WASM bytecode** and metadata about the code hash, enabling developers to verify and inspect deployed contracts.

## Supported Networks

* Mainnet

## Parameters Description

| **Parameter**  | **Type** | **Required** | **Description**                                                                        |
| -------------- | -------- | ------------ | -------------------------------------------------------------------------------------- |
| `request_type` | string   | Yes          | Must be set to `"view_code"`.                                                          |
| `finality`     | string   | Yes          | Defines how finalised the data should be: `"final"`, `"near-final"` or `"optimistic"`. |
| `account_id`   | string   | Yes          | The NEAR account ID of the contract to inspect.                                        |

## Request

**Base URL**

```bash
 https://go.getblock.io/<ACCESS_TOKEN>
```

**Example(cURL)**

```bash
curl --location 'https://go.getblock.io/<ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{"jsonrpc": "2.0",
"method": "query",
"params": {"request_type": "view_code", "finality": "near-final", "account_id": "staked.poolv1.near"},
"id": "getblock.io"}'
```

## Response Example

```json
{
    "jsonrpc": "2.0",
    "result": {
        "block_hash": "5xyv8AMZAknNgSZUug6uqKaTt2TX5hY3zxoEWLDD3mSV",
        "block_height": 169729125,
        "code_base64": "AGFzbQEAAAAB7wNBYAJ/fwF/YAF...",
        "hash": "J1arLz48fgXcGyCPVckFwLnewNH6j1uw79thsvwqGYTY"
    },
    "id": "getblock.io"
}
```

## Response Parameters Definition

| **Field**         | **Type** | **Description**                                                      |
| ----------------- | -------- | -------------------------------------------------------------------- |
| **block\_hash**   | string   | The hash of the block that contains the account state.               |
| **block\_height** | integer  | The height of the block at which the data was retrieved.             |
| **code\_base64**  | string   | The base64-encoded WebAssembly (WASM) code of the smart contract.    |
| **hash**          | string   | The SHA-256 hash of the contract’s WASM code, used for verification. |

## Use Cases

* Verify a contract’s **deployed bytecode** for audit or testing.
* Fetch **WASM code** for on-chain contract analysis tools.
* Ensure deployed code integrity for **security monitoring**.

## Code Example

**Node(Axios)**

```js
import axios from "axios";
let data = JSON.stringify({
  "jsonrpc": "2.0",
  "method": "query",
  "params": {
    "request_type": "view_code",
    "finality": "near-final",
    "account_id": "staked.poolv1.near"
  },
  "id": "getblock.io"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://go.getblock.io/<ACCESS_TOKEN>',
  headers: { 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
```

**Python(Requests)**

```python
import requests
import json

url = "https://go.getblock.io/<ACCESS_TOKEN>"

payload = json.dumps({
  "jsonrpc": "2.0",
  "method": "query",
  "params": {
    "request_type": "view_code",
    "finality": "near-final",
    "account_id": "staked.poolv1.near"
  },
  "id": "getblock.io"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

## Error Handling

| **HTTP Code**                 | **Error Message**       | **Description**                                       |
| ----------------------------- | ----------------------- | ----------------------------------------------------- |
| **404 Not Found**             | `Contract not found`    | The specified account has no deployed smart contract. |
| **500 Internal Server Error** | `Node processing error` | The NEAR node failed to process the query.            |
| **403 Forbidden**             | `RBAC: access denied`   | The Getblock access token is missing or incorrect     |

## Integration with Web3

By integrating `/query (view_code)` into dApp, developers can:

* Enable **smart contract inspection** directly from dashboards.
* Build **code verification tools** or explorers.
* Integrate with **CI/CD pipelines** for contract deployment validation.
* Enhance transparency for **on-chain AI and dApp ecosystems**.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.getblock.io/api-reference/near-protocol-near/near_query_view_code.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
