POSTview_global_contract_code

NEAR Mainnethttps://near-mainnet.nodit.io/

Returns the WASM binary of a global contract (an immutable shared contract) identified by its code hash, encoded in base64, together with its code hash. A global contract is code deployed once and referenced by many accounts.

Call the query method with request_type: "view_global_contract_code", passing the global contract's code hash in code_hash. If the node has never observed a global contract with that hash, it returns the NO_GLOBAL_CONTRACT_CODE error. Use view_global_contract_code_by_account_id for (updatable) global contracts deployed under an account ID.

Request Body
jsonrpcstringrequired
idstringrequired

Request ID. Any string; it is returned unchanged in the response.

methodstringrequired
request_typestring (enum)required

Query type. Fixed to view_global_contract_code for looking up global contract code by hash.

finalitystring (enum)

Specifies the block finality. Cannot be used together with block_id.

  • optimistic: the latest block the node has received (may be reorganized)
  • near-final: a Doomslug-final block (not reverted in most cases)
  • final: a fully finalized block
block_idinteger

Specifies the block to query by block height (integer) or block hash (base58 string). Cannot be used together with finality.

code_hashstringrequired

Code hash of the global contract to look up (base58). When an account uses this contract, the same value appears in global_contract_hash of the view_account response.

Responses
jsonrpcstring

JSON-RPC version

idstring

Request ID

code_base64string

The entire global contract WASM binary encoded in base64. The WASM can be up to about 4 MiB, and the base64 string is about 1.33 times longer. The example shows only the beginning.

hashstring

Hash of the global contract code (base58)

block_heightinteger

Block height.

Example: 220785385

block_hashstring

Base58-encoded 32-byte hash (block hash, chunk hash, transaction hash, etc.).

Example: 8EjuQRnAJiWkRmqxfexQFJWXXonuSMbz5AZziJLCWnWS

namestring (enum)

Error class. REQUEST_VALIDATION_ERROR (invalid request), HANDLER_ERROR (processing error), INTERNAL_ERROR (node internal error)

causeobject

The specific cause of the error.

namestring

Name of the error cause (e.g. UNKNOWN_BLOCK, UNKNOWN_ACCOUNT, PARSE_ERROR)

infoobject

Additional information about the error (block hash, height, account ID, etc.)

codeinteger

Legacy JSON-RPC error code (e.g. -32000 server error, -32700 parse error, -32601 method not found)

messagestring

Legacy error message

datastring

Legacy error details

X-API-KEY
RequestCU60
cURL
curl -X POST "https://near-mainnet.nodit.io/" \
  -H "X-API-KEY: {YOUR_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": "dontcare",
    "method": "query",
    "params": {
      "request_type": "view_global_contract_code",
      "finality": "final",
      "block_id": 220785385,
      "code_hash": "AoPRQSq7cvnZtqBSruN8xi7LzYCb3CY3zVFu9dWtPNJP"
    }
  }'
Response
Example · 200
{
  "jsonrpc": "2.0",
  "id": "dontcare",
  "result": {
    "code_base64": "AGFzbQEAAAABpQM3YAJ/fwBgAn9/AX9gA39/fwF/YAN/f38AYAF/AGAAAGAE",
    "hash": "AoPRQSq7cvnZtqBSruN8xi7LzYCb3CY3zVFu9dWtPNJP",
    "block_height": 220880589,
    "block_hash": "2fLiM1tgyhRgC13GdrWLwzJpmrALuHZ7CktiaM3sRYfe"
  }
}