query view code - NEAR Protocol
Example code for the query view code JSON-RPC method. Complete guide on how to use query view code JSON-RPC in GetBlock Web3 documentation.
Returns the deployed contract code (WASM, base64-encoded) for an account, with its hash. Uses method query with request_type view_code.
Method
queryParameters
The params object carries:
request_type
"view_code"
—
finality
"final"
—
account_id
"example.near"
—
Example
export NEAR_RPC=https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
curl -X POST "${NEAR_RPC}" \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "getblock.io", "method": "query", "params": {"request_type": "view_code", "finality": "final", "account_id": "example.near"}}'Response
Response Fields
code_base64
string
The contract WASM bytecode, base64-encoded
hash
string
Hash of the contract code
block_height
number
Height the state was read at
Use Cases
Verification: Fetch and hash the deployed WASM of a contract
Audit: Compare on-chain code against a known build
Error Handling
-32700 / Parse error
Parse error
The JSON request was malformed
-32601 / Method not found
Method not found
The method is unknown or disabled on this node version
HANDLER_ERROR
Requested data not found
The account, block, chunk, or transaction does not exist or is garbage-collected (use an archival node)
403 / RBAC: access denied
Access denied
The GetBlock access token is missing or incorrect
Was this helpful?