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 likeSolana 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.
{
"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......"
}
}{
"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": "[email protected]"
},
"description": {
"text": "swap NFT for MATIC and send MATIC to a friend",
"image": "https://valid_image_url......"
}
}Solana lambda batch invoke has the following properties:
- 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.
- 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.
- 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.
- Priority Fee(aka Compute Price): All invocations in the batch not signed externally will use the same priority fee.
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 transactionIds from this API response and querying it in Transaction Status API.
Replaying this APIOnce you get a
statusresponse asQUEUED, replaying this API doesn't give you the latest status; Replaying the same API with the sameIdempotency-Keyresults 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=="
}Fee Payer
The fee payer should be set to the sponsor's address before calling the API. The API will fail with an INVALID_SPONSOR error if the fee payer is not the sponsor's address.
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 StatusYou can find error status returned by the api here.
© Copyright 2024, Passbird Research Inc.
