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

# Invoke Lambda (Batch)

The API invokes a batch of lambda(smart contract) on Solana `without any gas` for both you and your users. The API also supports `external signers` if a transaction in the batch needs to be signed by someone other than the user. If you would like, you can also `cover the rent costs` for your users.

This is useful if you want to `send multiple` transactions in a single call e.g. approve a token, mint an NFT, and transfer the NFT on blockchains like`Solana` where the `transaction size is limited`. This `improves the user experience` by reducing the number of popups shown to the user to get their consent.

> 👍 Solana versioned transactions are supported

Below are some sample requests. You can also find end-to-end working code samples [here](https://github.com/PassbirdCo/MetaKeepCodeSamples/tree/main/solana/lambda).

```json Batch invocation as developer
{
  "invocations": [
    {
      "serializedTransactionMessage": "0x040001051d6a53......",
      "description": {
        "text": "Mint an NFT"
      }
    },
    {
      "signatures": [
        {
          "publicKey": "2k1ZTti7uQ1BZyMTscVLbzm3H74ncv2JdtLTio3FQxpb",
          "signature": "0x35068ad4b9a199a896a....."
        },
        {
          "publicKey": "HLETGSnF62q7ANP8SoWe7sxq7qrG3CEH6rJJhjaPadn8",
          "signature": "0xd2ac1cb04ae940388e73...."
        }
      ],
      "serializedTransactionMessage": "0x09120001051d6a53......",
      "description": {
        "text": "Sell an NFT"
      }
    },
    {
      "serializedTransactionMessage": "0x8002010204e84d3e7ed5......",
      "description": {
        "text": "Transfer 0.01 SOL"
      }
    }
  ],
  "description": {
    "text": "swap NFT for MATIC and send MATIC to a friend",
    "image": "https://valid_image_url......"
  }
}
```
```json Batch invocation as user
{
  "invocations": [
    {
      "serializedTransactionMessage": "0x040001051d6a53......",
      "description": {
        "text": "Mint an NFT"
      }
    },
    {
      "signatures": [
        {
          "publicKey": "2k1ZTti7uQ1BZyMTscVLbzm3H74ncv2JdtLTio3FQxpb",
          "signature": "0x35068ad4b9a199a896a....."
        },
        {
          "publicKey": "HLETGSnF62q7ANP8SoWe7sxq7qrG3CEH6rJJhjaPadn8",
          "signature": "0xd2ac1cb04ae940388e73...."
        }
      ],
      "serializedTransactionMessage": "0x09120001051d6a53......",
      "description": {
        "text": "Sell an NFT"
      }
    },
    {
      "serializedTransactionMessage": "0x8002010204e84d3e7ed5......",
      "description": {
        "text": "Transfer 0.01 SOL"
      }
    }
  ],
  "as": {
    "email": "dave@example.com"
  },
  "description": {
    "text": "swap NFT for MATIC and send MATIC to a friend",
    "image": "https://valid_image_url......"
  }
}
```

<br />

Solana lambda batch invoke has the following properties:

1. **Batch size**: You can execute up to 5 invocations in a single batch. Please let us know if you want to execute more than 5 invocations.
2. **Parallel execution**: All invocations in the batch are executed in parallel without any ordering guarantee. It's also possible for some invocations to fail while others succeed.
3. **Blockhash**: All invocations in the batch not signed externally will use the same blockhash. There is a possibility of duplicate transactions if two invocations in the batch are the same.
4. **Priority Fee(aka Compute Price)**: All invocations in the batch not signed externally will use the same priority fee.

## Invoking without `as` user

If you don't provide an `as` user in the request body, lambda will be invoked from your developer account and a transaction will be raised and submitted to the Queue on the blockchain. MetaKeep, behind the scenes, employs several strategies to make sure transactions succeed, and at the lowest cost.

You can get the status of this blockchain transaction by querying for transaction status by copying the transactionIds from this API response and querying it in [Transaction Status API](https://docs.metakeep.xyz/reference/v1apptransactionstatus).

> ❗️ Replaying this API
>
> Once you get a `status` response as `QUEUED`, replaying this API doesn't give you the latest status; Replaying the same API with the same [`Idempotency-Key`](https://docs.metakeep.xyz/reference/idempotency-key) results in the same response, always with status-`QUEUED`. You must query the [Transaction Status](https://docs.metakeep.xyz/reference/v1apptransactionstatus) API for the latest status.

As you would learn from the [Transaction Status](https://docs.metakeep.xyz/reference/v1apptransactionstatus) API docs, if a transaction failed, MetaKeep would have exhausted all feasible smart AI-based strategies to recover from failure, that would have been attempted by humans and the "FAILED" status, if shown, is final.

## Invoking with `as` user

If you provide an `as` user in the request body, you will get a `consentToken` back and you will have to use [Get Consent](https://docs.metakeep.xyz/reference/get-consent) flow to finish the lambda invocation. Here, the developer is agreeing to pick up the gas fee on execution so that the user doesn't have to know/understand the concept of gas. MetaKeep, behind the scenes, employs several strategies to make sure transactions succeed, and at the lowest cost.

```json Sample Response
{
  "status": "USER_CONSENT_NEEDED",
  "consentToken": "CrgBAQIDAHgtrXLM7Takfd-ccn6FAthYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw=="
}
```

## Fee Payer

The `fee payer` should be set to the [sponsor's address](https://docs.metakeep.xyz/reference/v2applambdagetsponsor-solana) before calling the API. The API will fail with an `INVALID_SPONSOR` error if the fee payer is not the [sponsor's address](https://docs.metakeep.xyz/reference/v2applambdagetsponsor-solana).

## Latest Blockhash

If there are `no external signers`, you can set the latest blockhash to any value. To improve the success rate of the transaction, the API will automatically fetch the latest blockhash and use it to sign and broadcast the transaction.

If there are `external signers`, you should set the latest blockhash by fetching it from a Solana node before calling the API. The API `cannot` update the latest blockhash if there are external signers.

## Priority Fee(aka Compute Price)

If you want to use the `priority fee`, please include the `compute price` instruction in the message.

If there are `no external signers`, you can set the `compute price` to any value. The lambda will `automatically reprice the transaction` if needed based on the current Solana network conditions.

If there are `external signers`, you will have to set the `compute price` yourself by fetching it from a Solana node before calling the API. The API `cannot` update the `compute price` if there are external signers.

There is a limit to the `compute price` that can be provided. The maximum `compute price` that can be set currently is `1000000(1 million)`. The API will fail with a `PRIORITY_FEE_TOO_HIGH` error if the `compute price` exceeds this limit. We also recommend setting the `compute budget` too to avoid unnecessary fee charges.

## Rent Payment

Please reach out to us if you need rent payment enabled for your app :)

## Error Status

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

© Copyright 2024, Passbird Research Inc.

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "production-solana-lambda",
    "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/invoke/multiple": {
      "post": {
        "summary": "Invoke Lambda (Batch)",
        "description": "",
        "operationId": "v2applambdainvokemultiple-solana",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "description": "An idempotency key is a unique value generated by the client which the server uses to recognize subsequent retries of the same request. This allows developers to safely retry requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit and you do not receive a response. [Read more](/reference/idempotency-key)",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "invocations",
                  "description"
                ],
                "properties": {
                  "invocations": {
                    "type": "array",
                    "description": "List of lambdas to invoke in the transaction.",
                    "items": {
                      "properties": {
                        "signatures": {
                          "type": "array",
                          "description": "List of signatures from external signers. This can be left empty if there are no external signers.",
                          "items": {
                            "properties": {
                              "publicKey": {
                                "type": "string",
                                "description": "Public key of the external signer"
                              },
                              "signature": {
                                "type": "string",
                                "description": "Signature of the transaction message by the external signer"
                              }
                            },
                            "required": [
                              "publicKey",
                              "signature"
                            ],
                            "type": "object"
                          }
                        },
                        "serializedTransactionMessage": {
                          "type": "string",
                          "description": "Serialized transaction message in hex format(`prefixed with 0x`). You can get this by calling `transaction.serializeMessage().toString(\"hex\")`"
                        },
                        "description": {
                          "type": "object",
                          "description": "The human understandable explanation for this transaction. Useful for presenting to the user as an extra information ex: `Swap wBTC to USDC`, and for auditing purposes. The description should include a text and an optional image.",
                          "required": [
                            "text"
                          ],
                          "properties": {
                            "text": {
                              "type": "string",
                              "description": "Human understandable text explaining the transaction."
                            }
                          }
                        }
                      },
                      "required": [
                        "serializedTransactionMessage"
                      ],
                      "type": "object"
                    }
                  },
                  "description": {
                    "type": "object",
                    "description": "The human understandable explanation for this transaction. Useful for presenting to the user as an extra information ex: `Swap wBTC to USDC`, and for auditing purposes. The description should include a text and an optional image.",
                    "required": [
                      "text"
                    ],
                    "properties": {
                      "text": {
                        "type": "string",
                        "description": "Human understandable text explaining the transaction."
                      },
                      "image": {
                        "type": "string",
                        "description": "An optional image URL to show along with the text."
                      }
                    }
                  },
                  "as": {
                    "type": "object",
                    "description": "Invoke lambda `as` this user. If this is not set, lambda will be invoked from your developer account.",
                    "properties": {
                      "email": {
                        "type": "string",
                        "description": "Email address of the user"
                      }
                    }
                  }
                }
              },
              "examples": {
                "Batch Invocation as developer": {
                  "value": {
                    "invocations": [
                      {
                        "serializedTransactionMessage": "0x040001051d6a53......",
                        "description": {
                          "text": "Mint an NFT"
                        }
                      },
                      {
                        "signatures": [
                          {
                            "publicKey": "2k1ZTti7uQ1BZyMTscVLbzm3H74ncv2JdtLTio3FQxpb",
                            "signature": "0x35068ad4b9a199a896a....."
                          },
                          {
                            "publicKey": "HLETGSnF62q7ANP8SoWe7sxq7qrG3CEH6rJJhjaPadn8",
                            "signature": "0xd2ac1cb04ae940388e73...."
                          }
                        ],
                        "serializedTransactionMessage": "0x09120001051d6a53......",
                        "description": {
                          "text": "Sell an NFT"
                        }
                      },
                      {
                        "serializedTransactionMessage": "0x8002010204e84d3e7ed5......",
                        "description": {
                          "text": "Transfer 0.01 SOL"
                        }
                      }
                    ],
                    "description": {
                      "text": "swap NFT for MATIC and send MATIC to a friend",
                      "image": "https://valid_image_url......"
                    }
                  }
                },
                "Batch invocation as user": {
                  "value": {
                    "invocations": [
                      {
                        "serializedTransactionMessage": "0x040001051d6a53......",
                        "description": {
                          "text": "Mint an NFT"
                        }
                      },
                      {
                        "signatures": [
                          {
                            "publicKey": "2k1ZTti7uQ1BZyMTscVLbzm3H74ncv2JdtLTio3FQxpb",
                            "signature": "0x35068ad4b9a199a896a....."
                          },
                          {
                            "publicKey": "HLETGSnF62q7ANP8SoWe7sxq7qrG3CEH6rJJhjaPadn8",
                            "signature": "0xd2ac1cb04ae940388e73...."
                          }
                        ],
                        "serializedTransactionMessage": "0x09120001051d6a53......",
                        "description": {
                          "text": "Sell an NFT"
                        }
                      },
                      {
                        "serializedTransactionMessage": "0x8002010204e84d3e7ed5......",
                        "description": {
                          "text": "Transfer 0.01 SOL"
                        }
                      }
                    ],
                    "as": {
                      "email": "dave@example.com"
                    },
                    "description": {
                      "text": "swap NFT for MATIC and send MATIC to a friend",
                      "image": "https://valid_image_url......"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Invoke as a developer": {
                    "value": "{\n  \"status\": \"QUEUED\",\n  \"transactions\": [\n    {\n      \"status\": \"QUEUED\",\n      \"transactionId\": \"38cae336-9bc2-4b69-9141-3c85edf26f28\",\n      \"transactionSignature\": \"3MRukZUmWhn6kKisa49fQXLu8sZWR5FuyoPczmmPgvaxwDZttxgrHheWADN2HH6vo8wZnCTDc2X1BmWwtzVMvsrS\",\n      \"transactionChainScanUrl\": \"https://explorer.solana.com/tx/3MRukZUmWhn6kKisa49fQXLu8sZWR5FuyoPczmmPgvaxwDZttxgrHheWADN2HH6vo8wZnCTDc2X1BmWwtzVMvsrS?cluster=devnet\"\n    },\n    {\n      \"status\": \"QUEUED\",\n      \"transactionId\": \"94be5e32-744e-458f-b8f5-d6882360816c\",\n      \"transactionSignature\": \"3tCRSonjNK6DyKWGb6sdc9i29j8VU6GMFndAtNF4xFh6kVDFihsoWvhSP9xNMP3KwWWk4Lug5zAtHv9LgewMjBdk\",\n      \"transactionChainScanUrl\": \"https://explorer.solana.com/tx/3tCRSonjNK6DyKWGb6sdc9i29j8VU6GMFndAtNF4xFh6kVDFihsoWvhSP9xNMP3KwWWk4Lug5zAtHv9LgewMjBdk?cluster=devnet\"\n    },\n    {\n      \"status\": \"QUEUED\",\n      \"transactionId\": \"df2294c0-24af-4cc1-afa3-0f2c89ec8b85\",\n      \"transactionSignature\": \"2S3RaKieYzg7abV85nL4CJNWtQpYAg4PJ4yVGpQP1u6wXq5uy4H9roiH2pF1MPPpQB2JeqoANjsFnLtM7wiUtr2h\",\n      \"transactionChainScanUrl\": \"https://explorer.solana.com/tx/2S3RaKieYzg7abV85nL4CJNWtQpYAg4PJ4yVGpQP1u6wXq5uy4H9roiH2pF1MPPpQB2JeqoANjsFnLtM7wiUtr2h?cluster=devnet\"\n    }\n  ]\n}"
                  },
                  "Invoke as a user": {
                    "value": "{\n  \"status\": \"USER_CONSENT_NEEDED\",\n  \"consentToken\": \"CrgBAQIDAHgtrXLM7Takfd-ccn6FAthYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw==\"\n}"
                  }
                },
                "schema": {
                  "oneOf": [
                    {
                      "title": "Invoke as a developer",
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "QUEUED"
                        },
                        "transactions": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "status": {
                                "type": "string",
                                "example": "QUEUED"
                              },
                              "transactionId": {
                                "type": "string",
                                "example": "38cae336-9bc2-4b69-9141-3c85edf26f28"
                              },
                              "transactionSignature": {
                                "type": "string",
                                "example": "3MRukZUmWhn6kKisa49fQXLu8sZWR5FuyoPczmmPgvaxwDZttxgrHheWADN2HH6vo8wZnCTDc2X1BmWwtzVMvsrS"
                              },
                              "transactionChainScanUrl": {
                                "type": "string",
                                "example": "https://explorer.solana.com/tx/3MRukZUmWhn6kKisa49fQXLu8sZWR5FuyoPczmmPgvaxwDZttxgrHheWADN2HH6vo8wZnCTDc2X1BmWwtzVMvsrS?cluster=devnet"
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "title": "Invoke as a user",
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "USER_CONSENT_NEEDED"
                        },
                        "consentToken": {
                          "type": "string",
                          "example": "CrgBAQIDAHgtrXLM7Takfd-ccn6FAthYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw=="
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
```