---
updatedAt: 2025-07-26T16:54:38.000Z
agentTools:
  projectIndex: https://docs.metakeep.xyz/llms.txt
---

# Read Lambda Data

After the lambda is created from the `/v2/app/lambda/create` or imported using `/v2/app/lambda/import` API call, use this API to read data from the read-only or getter function(also known as the view-only function in solidity). Calling a non-read function will result in an error.

JSON response `data` field contains the return value of the read-only function. The `data` field format follows specification [here](https://docs.metakeep.xyz/reference/lambda-101#solidity-types-to-lambda-types). Here are some examples:

```json Read tokenURI response
// Read smart contract data: tokenURI(uint256 tokenId)
{
  "status": "SUCCESS",
  "data": "https://api.dev.metakeep.xyz/v2/nft/metadata?chain=80002&collection=0x5059221e0971b1761f71a9619932c2b395c266d2&token=70247059"
}
```
```json Read ownerOf response
// Read smart contract data: ownerOf(uint256 tokenId)
{
  "status": "SUCCESS",
  "data": "0x6B40cA2814198A37BA5798B0C5EE1A2E029b997f"
}
```
```json Read array response
// Read from a function that returns an array
{
  "status": "SUCCESS",
  "data": [
    "0x6B40cA2814198A37BA5798B0C5EE1A2E029b997f",
    "123"
  ]
}
```

If the contract function throws an error, the response will contain the error message and the status will be `FUNCTION_FAILURE`. Here's an example

```json Contract function failure response
/*  This function gets balance of the user.

    function balanceOf(address of) public view virtual {
        require(to != address(0), "ERC721: balance query for the zero address");
        return _balance[of];
    }
*/

// Call balanceOf with zero address.
// The response will have the error message.
{
  "status": "FUNCTION_FAILURE",
  "failureReason": "ERC721: balance query for the zero address"
}
```

> 👍 This API doesn't consume any gas.
>
> You don't need to pay any gas fee when using this API. It's okay to call this API several times without having to worry about paying for blockchain transactions.

## Data Reading Limits

The API has limits on the amount of data(**gas< 200M**) that can be returned in a single call and the time it takes to execute the function call. Trying to read too much data can result in failure and cause a **poor user experience** due to higher latency. This also prevents reading from functions that can go in an infinite loop.

For best results, we recommend the following:

* **Only read the data you need.** If you need to read a lot of data, consider breaking it up into multiple calls.
* **Use Pagination**. If you need to read all data, design your function so that instead of returning all the data, it returns a page of data. You can then use the pagination parameters to retrieve the next page of data.
* **Store data in database**. Consider storing the large data in your own database instead (SQL, S3, etc).

*Note that if you have already deployed the lambda contract, you can update the contract to add pagination parameters if the contract is upgradable or deploy a new contract with pagination parameters which will read the data from your existing contract.*

## Error Status

> 🚧 Api Error Status
>
> You can find error status returned by the api [here](https://docs.metakeep.xyz/reference/api-error-status#v2applambdaread).

© Copyright 2024, Passbird Research Inc.

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "production",
    "version": "3.4"
  },
  "servers": [
    {
      "url": "https://api.metakeep.xyz/"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/v2/app/lambda/read": {
      "post": {
        "summary": "Read Lambda Data",
        "description": "",
        "operationId": "v2applambdaread",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "lambda",
                  "function"
                ],
                "properties": {
                  "lambda": {
                    "type": "string",
                    "description": "Hex encoded lambda address. This is obtained from a previous `/v2/app/lambda/create` or  `/v2/app/lambda/import` API call"
                  },
                  "function": {
                    "type": "object",
                    "description": "Lambda Function with arguments to read the data from in the format `{ name: \"function_name\", args: [] }`. `Args` list can be left empty if the function takes no arguments.",
                    "required": [
                      "name"
                    ],
                    "properties": {
                      "name": {
                        "type": "string",
                        "description": "Function name.",
                        "default": "function_name"
                      },
                      "args": {
                        "type": "array",
                        "description": "Array of function arguments. This can be left empty if the function takes no arguments. Arguments should be sent in the format described [here](https://docs.metakeep.xyz/reference/lambda-101#solidity-types-to-lambda-types).",
                        "default": [
                          "123"
                        ],
                        "items": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n  \"status\": \"SUCCESS\",\n  \"data\": \"2.05\"\n}"
                  },
                  "Read array": {
                    "value": "{\n  \"status\": \"SUCCESS\",\n  \"data\": [\n    \"2.05\",\n    \"0x1234\"\n  ]\n}"
                  },
                  "Contract function failure": {
                    "value": "{\n  \"status\": \"FUNCTION_FAILURE\",\n  \"failureReason\": \"ERC721: balance query for the zero address\"\n}"
                  }
                },
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "SUCCESS"
                        },
                        "data": {
                          "type": "string",
                          "example": "2.05"
                        }
                      }
                    },
                    {
                      "title": "Read array",
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "SUCCESS"
                        },
                        "data": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "example": "2.05"
                          }
                        }
                      }
                    },
                    {
                      "title": "Contract function failure",
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "FUNCTION_FAILURE"
                        },
                        "failureReason": {
                          "type": "string",
                          "example": "ERC721: balance query for the zero address"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
```