Import and Invoke Popular Contracts

LambdaV3 supports importing any externally deployed contract. This can be a contract that you have deployed or any popular contract like Uniswap, Aave, USDC, etc. This opens up numerous possibilities for seamlessly integrating your DAPP with popular smart contracts. With LambdaV3, possibilities are endless.

In this tutorial, we will discuss importing popular DEX(SushiSwap) and then swapping MATIC for USDC using LambdaV3.

🚧

Note that imported contracts are only supported when using Business Wallets

Importing DEX

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

You can find an end-to-end working demo here.

πŸ“˜

This tutorial only works on Polygon Mainnnet

Due to liquidity issue, this tutorial is designed to work only on Polygon Mainnet.

Step 1: Get the ABI of the contract

There are different ways by which you can get the ABI of a contract. In this tutorial, we will get the ABI of the contract by using the Polygonscan API as shown below:

  const response = await fetch(
    "https://api.polygonscan.com/api?module=contract&action=getabi&address=" +
      process.env.SUSHISWAP_ROUTER_ADDRESS
  );

Step 2: Make a POST request to the lambda/import API

Let's constructor the request body using the ABI that we got in the previous step as shown below.

{
  "name": <LAMBDA_NAME>,
  "lambda": <ADDRESS_OF_THE_CONTRACT>,
  "abi": <ABI_OF_THE_CONTRACT>
}

On success, this is what you should see as the response from the Import Lambda API:

{
  "status": "SUCCESS"
}

Running the demo

You can find an end-to-end working demo here.

Step 1: Import the contract

Navigate to the lambda/business-wallet/token-swap/scripts directory. Then, run the following command:

npm install
npm run importContract

Step 2: Swap tokens

Run the following command:

npm run swapMaticForUSDC

This will swap MATIC for USDC.

Next steps

Voila! You have successfully imported the contract and invoked the method πŸŽ‰πŸŽ‰.