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",
"description": {
"text": "Mint an NFT for 0.03 MATIC"
}
}
},
{
"call": {
"lambda": "0xc5fd96683659C62b5db12F82dB330Af04d7efaEC",
"function": {
"name": "transfer",
"args": [
"123",
"0x3ecb936ef8cc5757341078b6137aabec1e21d6af"
]
},
"description": {
"text": "Sell NFT for 0.05 MATIC"
}
}
},
{
"pay": {
"to": {
"ethAddress": "0x8dc572d9FefB6A8d6c76897AF11dDf1dEbCEAfd0"
},
"amount": "0.05",
"description": {
"text": "Transfer proceeds to a friend"
}
}
}
],
"as": {
"email": "[email protected]"
},
"using": "BUSINESS_WALLET",
"description": {
"text": "swap NFT for MATIC and send MATIC to a friend",
"image": "https://valid_image_url......"
}
}
{
"invocations": [
{
"call": {
"lambda": "0xc5fd96683659C62b5db12F82dB330Af04d7efaEC",
"function": {
"name": "mint",
"args": [
"123"
]
},
"pay": "0.03",
"description": {
"text": "Mint an NFT for 0.03 MATIC"
}
}
}
],
"using": "BUSINESS_WALLET",
"description": {
"text": "purchase an NFT"
}
}
{
"invocations": [
{
"pay": {
"to": {
"ethAddress": "0x8dc572d9FefB6A8d6c76897AF11dDf1dEbCEAfd0"
},
"amount": "0.05",
"description": {
"text": "Transfer proceeds to a friend"
}
}
}
],
"as": {
"email": "[email protected]"
},
"using": "BUSINESS_WALLET",
"description": {
"text": "transfer 0.05 MATIC to your friend",
"image": "https://valid_image_url......"
}
}
Lambda batch invoke has the following properties:
- 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, the NFT will not be sold if the swap fails.
- 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.
- Batch size: You can execute up to 10 invocations in a single batch. If you want to execute more than 10 invocations, please let us know.
- BUSINESS_WALLET: Lambda batch is only supported when using
BUSINESS_WALLET
.
Invocation types
Lambda batch invoke supports 2 types of invocations:
- 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 ispayable
, you can also specify thepayment(aka value transfer)
to send to the function. - 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
as
userIf 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 asQUEUED
, replaying this API doesn't give you the latest status; Replaying the same API with the sameIdempotency-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
as
userIf 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.