Invoke Lambda method using developer business wallet(Zero-Friction and Gasless)
In this tutorial, we will discuss two groundbreaking features that amplify the Metakeep Lambda capabilities: Business wallets
and Atomic batch transactions
. We will also take a look at how to make payments(aka value transfer)
. All this can be easily accomplished without digging into the underlying blockchain complexities like nodes, transaction fees, nonces, and much more.
Invoking contract method using business wallets
In this tutorial, like earlier, we will start with a basic Voting Smart contract from our GitHub repo.
You can find an end-to-end working demo here.
Step 1: Copy the address of the Lambda that you want to invoke.
You should have gotten the Lambda address as the output of the previous tutorial.
If you have lost the address, you can make a request to List Lambdas API to get the list of all deployed Lambdas. Else, you can always deploy a new contract by following the previous tutorial.
Step 2: Make a Post request to the invoke API
To use business wallets, you need to send BUSINESS_WALLET
in the using
parameter of the lambda invocation.
To call a single lambda contract, use the Invoke Lambda API. Here's what the request looks like:
{
"lambda": "0x1234.....",
"function": {
"name": "function_name",
// keep it empty in case of no args
"args": [
"arg1",
"arg2"
]
},
"pay": "0.01",
"reason": "reason for invocation",
"using": "BUSINESS_WALLET"
}
On the other hand, if you are looking to make multiple calls and payments, then use the Invoke Lambda (Batch) API. Here's what the request looks like:
{
"invocations": [
// First call with payment
{
"call": {
"lambda": "0x1234....",
"function": {
"name": "function_name",
"args": [
"arg1",
"arg2"
]
},
"pay": "0.01",
"reason": "reason for invocation"
}
},
// Second call with payment
{
"call": {
"lambda": "0xab12....",
"function": {
"name": "function_name1",
"args": [
"arg3",
"arg4"
]
},
"pay": "0.02",
"reason": "reason for this invocation"
}
},
// Payment to an address
{
"pay": {
"to": {
"ethAddress": "0xadd...."
},
"amount": "1.11"
}
}
],
"reason": "high level reason for the batch",
"using": "BUSINESS_WALLET"
}
Running the Demo
You can find an end-to-end working demo here. Follow these steps to run the Demo:
Step 1: Prerequisite
Before proceeding, you need to complete the first part of the tutorial. Once you have the lambda address, store it somewhere because we would need that in the next step.
Also, make sure that your developer Business Wallet has sufficient tokens for the payment(value transfer)
.
Step 2: Update the .env file
Update the .env file with the API key, and the Lambda address from the previous step.
Step 3: Run the script
Navigate to the lambda/business-wallet/batch-transactions/scripts
directory. Then, run the command:
npm install
npm run registerAndVote
The script will run a batch of size 3(create a proposal, stake, and then vote) using the Invoke Lambda (Batch) API. Note that only 1 transaction will be executed on the blockchain.
Next steps
Voila! You have invoked multiple functions and issued payments using MetaKeep Lambda Business Wallets 🎉🎉.
Updated about 1 year ago