Decode the byte array returned by a NEAR view function

A successful view call can appear to return a list of numbers in a JSON client. Those numbers represent the contract’s return bytes. The contract ABI determines the next decoding step.

Encode arguments according to the contract ABI

For a JSON method taking an empty object, UTF-8 bytes for {} become e30= in base64. POST this query to a testnet endpoint serving the example contract, or replace the account and method with your own.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "query",
  "params": {
    "request_type": "call_function",
    "finality": "final",
    "account_id": "contract.rpc-examples.testnet",
    "method_name": "get_greeting",
    "args_base64": "e30="
  }
}

Decode once, then parse the payload

If result.result is [34,111,107,34], the UTF-8 text contains the JSON string "ok", including its quotation marks. In JavaScript use JSON.parse(new TextDecoder().decode(Uint8Array.from(response.result.result))) for a JSON-returning method. Logs live in a separate field.

For a binary return type, run the declared binary decoder on the bytes instead. Preserve empty bytes as their own case before attempting JSON parsing.

Sources