Create Lambda

In this tutorial, we are excited to discuss LambdaV3 and the powerful Business Wallets. Unlike its predecessor, LambdaV2 which required developers to make modifications to the smart contracts, LambdaV3 offers an efficient and seamless deployment process without requiring any changes to the contract code.

Getting Started with Lambda Business Wallets

The first step is to get an API key. To do so, sign up here.

In this tutorial, 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: Compile your contract

Once you have developed and tested your smart contract, compile your contract to get the contract bytecode and ABI.

Step 2: Prepare a POST request to the lambda/create API

Let's construct the request body using all the information from the previous step as shown below.

{
  "name": <Lambda_Name>,
  "constructor" : { args : ["arg1", "arg2"]},
  "bytecode" : <Bytecode>,
  "abi" : < ABI >
}

Step 3: Call create API to deploy your contract

To deploy your contract, make a POST request to the API. For this, you would require an API Key and an Idempotency Key. Here's how you would make a request to API.

const fetch = require('node-fetch');

const url = 'https://api.metakeep.xyz/v2/app/lambda/create';
const request_body = {
  "name": <Lambda_Name>,
  "constructor" : { args : ["arg1", "arg2"]},
  "bytecode" : <Bytecode>,
  "abi" : < ABI >
}

const options = {
  method: 'POST',
  headers: {
  'Accept': 'application/json',
  'Content-Type': 'application/json',
  'x-api-key': <API_KEY>,
  'Idempotency-Key’: <IDEMPOTENCY_KEY>
  },
  body: JSON.stringify(request_body)
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));

This is what you should see as the response from the create API:

{
  status: 'QUEUED',
  transactionId: '1f424819-4ddc-4bcb-9054-ca75b2719f9b',
  transactionHash: '0x9b304e368e0d5d6398c6dd6ad5e216bfc80fefebb99897e8238633ef1d957b7a',
  transactionChainScanUrl: 'https://mumbai.polygonscan.com/tx/0x9b304e368e0d5d6398c6dd6ad5e216bfc80fefebb99897e8238633ef1d957b7a',
  lambda: '0x17192E38Db788a15432149C93101C6cB040dE7C2'
}

📘

Note the lambda field in the response

The lambda field gives you the address of your smart contract. Ensure that you keep the address recorded because it will be used for lambda invocation (You can always get the list of your deployed lambdas using the list lambdas API).

Running the demo

You can find an end-to-end working demo here. Follow these steps to run the demo:

Step 1: Compile the contract

Navigate to the lambda/business-wallet/batch-transactions/smart-contractsdirectory. Then, run the command:

npm install
npx hardhat compile

Step 2: Update the .env file

Update the API key in the .env file.

Step 3: Run the Script

Navigate to the lambda/business-wallet/batch-transactions/scripts directory. Then run the command:

npm install
npm run create

The demo will deploy the lambda, and wait for the transaction mining. You will see the created lambda address in the output of the script.

Next Steps

Voila! You have deployed your first lambda contract with business wallet🎉🎉.

Next, we will discuss making batch calls to the deployed contract using business wallet.