Invoke Lambda (Batch)

After lambdas are created from the /v2/app/lambda/create API call or imported using the /v2/app/lambda/import API, use this API to execute a batch of lambda invocations(function calls and payments(aka value transfer)) in a single transaction. This API is useful if you want to execute multiple lambda invocations in a single transaction e.g. sell your NFT, swap the proceeds for USDC, and send the USDC to your friend.

📘

Lambda batch invoke is only supported with the BUSINESS_WALLET

Here are some sample requests:

{
  "invocations": [
    {
      "call": {
        "lambda": "0xc5fd96683659C62b5db12F82dB330Af04d7efaEC",
        "function": {
          "name": "mint",
          "args": [
            "123"
          ]
        },
        "pay": "0.03",
        "reason": "Mint an NFT for 0.03 MATIC"
      }
    },
    {
      "call": {
        "lambda": "0xc5fd96683659C62b5db12F82dB330Af04d7efaEC",
        "function": {
          "name": "transfer",
          "args": [
            "123",
            "0x3ecb936ef8cc5757341078b6137aabec1e21d6af"
          ]
        },
        "reason": "Sell NFT for 0.05 MATIC"
      }
    },
    {
      "pay": {
        "to": {
          "ethAddress": "0x8dc572d9FefB6A8d6c76897AF11dDf1dEbCEAfd0"
        },
        "amount": "0.05",
        "reason": "Transfer proceeds to a friend"
      }
    }
  ],
  "as": {
    "email": "[email protected]"
  },
  "using": "BUSINESS_WALLET",
  "reason": "swap NFT for MATIC and send MATIC to a friend"
}
{
  "invocations": [
    {
      "call": {
        "lambda": "0xc5fd96683659C62b5db12F82dB330Af04d7efaEC",
        "function": {
          "name": "mint",
          "args": [
            "123"
          ]
        },
        "pay": "0.03",
        "reason": "Mint an NFT for 0.03 MATIC"
      }
    }
  ],
  "using": "BUSINESS_WALLET",
  "reason": "purchase an NFT"
}
{
  "invocations": [
    {
      "pay": {
        "to": {
          "ethAddress": "0x8dc572d9FefB6A8d6c76897AF11dDf1dEbCEAfd0"
        },
        "amount": "0.05",
        "reason": "Transfer proceeds to a friend"
      }
    }
  ],
  "as": {
    "email": "[email protected]"
  },
  "using": "BUSINESS_WALLET",
  "reason": "transfer 0.05 MATIC to your friend"
}

Lambda batch invoke has the following properties:

  1. Atomicity: All the invocations in the batch are executed as an atomic unit. If any invocation fails, the entire batch will fail and all the changes will be reverted. E.g. if you are selling an NFT and swapping the proceeds for USDC, if the swap fails, the NFT will not be sold.
  2. Ordering: Invocations are executed in the order they are specified in the request. E.g. if you are selling an NFT and swapping the proceeds for USDC, the NFT will be sold first and then the proceeds will be swapped for USDC.
  3. Batch size: You can execute up to 5 invocations in a single batch. If you want to execute more than 5 invocations, please let us know.
  4. BUSINESS_WALLET: Lambda batch is only supported when using BUSINESS_WALLET.

Invocation types

Lambda batch invoke supports 2 types of invocations:

  1. Function call: Use this invocation type to call a lambda function. You can specify the lambda function to call, the function name, and the function arguments. If the function is payable, you can also specify the payment(aka value transfer) to send to the function.
  2. Payment: Use this invocation type to send a payment(aka value transfer) to a user or a contract. You can specify the user or contract to send the payment to and the amount to send. If you are sending a payment to a contract, make sure that the contract has a payable fallback function.

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 transactionId from this API response and querying it in Transaction Status API.

❗️

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 results in the same response, always with status-QUEUED. You must query the Transaction Status API for the latest status.

As you would learn from the Transaction Status 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 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.

{
  "status": "USER_CONSENT_NEEDED",
  "consentToken": "CrgBAQIDAHgtrXLM7Takfd-ccn6FAthYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw=="
}

Gas Limit

This API currently has gas limit set to 2000000(2M). If you need a higher gas limit, please let us know.

Gas Price

The API sets the right gas price for the transaction based on AI and statistical analysis of the current network conditions for fast and reliable transaction confirmation. If you want even faster confirmation, you can tune the transaction speed in the app settings.

Error Status

🚧

Api Error Status

You can find error status returned by the api here.

© Copyright 2024, Passbird Research Inc.

Language
Authorization
Header
Click Try It! to start a request and see the response here!