Deploy a Serverless Maker Bot on AirSwap (Part 2)

Graham Perich
Dec 2, 2019 · 5 min read

In this two-part tutorial, learn how to quickly set up a maker for AirSwap Instant using the new AirSwap Maker Kit and zero-config deployment with Vercel.

AirSwap is a peer-to-peer token trading network. In Part 1 of this tutorial we built a simple maker bot, ran it locally, and queried it. Now, we’ll walk through a few final steps to deploy our maker to the cloud and query it via AirSwap Instant.

Image for post
Image for post

Deploying with Vercel

This is probably the easiest part of the tutorial, because Vercel makes deployment so easy. Simply run the following command inside of

$ now

When the deployment finishes, you’ll see your maker address printed out. Keep this handy, we’ll be using it shortly. It should be formatted as

This address shouldn’t be longer than 32 characters including the https:// prefix. If it’s longer, consider changing the “name” of your maker in to something shorter, or using a shorter Vercel username.

Approve tokens for trading

We need to approve the Swap contract to move tokens on our behalf in order for it to work properly. This is a fundamental necessity of almost every kind of decentralized exchange system on Ethereum. You’ll need to complete this step for any token that you want your maker to trade, but you should only ever have to perform it once per token. The AirSwap CLI includes a command to automate token approvals, so let’s take care of that now.

On the command line, open the file that you created in the directory and copy the value to import it into the CLI.

$ airswap account:import

Now we’re ready to run the token approval script.

$ airswap token:approve

When prompted for the address of the token you want to approve, paste in the Rinkeby DAI address. In Part 1, we got some test DAI from the Compound Faucet. Paste the address into the prompt and hit enter/return on your keyboard.

0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea

Finally, double-check that everything is correct and type “yes”. Your transaction will now be submitted to the Ethereum network, and you just have to wait a minute or two for the miners to finalize it.

Image for post
Image for post

Using the Indexer

At the end of Part 1, we queried our maker locally by pasting our address into the prompt. We could query any maker directly peer-to-peer in this fashion, but what if we don’t already know a maker’s location in advance? How can we discover other traders on the network? That’s where the Indexer smart contract comes in. An Indexer is a smart contract that aggregates trade intents. In our example we are trading DAI/WETH, so we will publish an intent to the indexer that signals this to the network. Then, other traders who are interested in trading DAI/WETH can discover our address on the indexer and ask for a quote or order. In fact, this is exactly the method that AirSwap Instant employs to help traders discover each other. AirSwap Maker Kit also has a script for setting Indexer intents, which we’ll use below.

First, approve the indexer to stake AST

$ airswap indexer:enable
Image for post
Image for post

Now, we can decide how much we want to stake. The more we stake, the higher up on the list we’ll appear when traders query the indexer. You can acquire up to 5000 test AST from the Rinkeby faucet. You can also run the command to view the current state of the list.

airswap indexer:set
Image for post
Image for post
Replace “m.tutorial.now.sh” with the URL of your maker.

Querying your maker on AirSwap Instant

Now that we’ve completed all the necessary steps, we should be able to communicate with our maker on the web. To verify this, let’s head over to the development version of AirSwap Instant running on the Rinkeby test net: https://instant.development.airswap.io

Using MetaMask, switch to a different address than the one you’re using for your maker. Change the base asset in the top right to “WETH” (we set our maker to trade DAI for WETH).

Image for post
Image for post

Now, open the Chrome Network debugger and request an order for some DAI. You should see your maker appear in the network activity, and one of the quotes in the “All Quotes” results should be from your maker. Congratulations, your maker is now online 🎉

Image for post
Image for post

Now that you have a working end-to-end example, you can start to customize the code and add your own logic. You should also check out your Vercel Dashboard. It provides many helpful tools such as log monitoring that will help you debug your deployed maker.

Note: The information contained in this blog post is solely for information purposes and does not constitute financial or legal advice. Users agree that their activity and conduct in connection with their use of AirSwap or any tools described in this post, including any resultant transactions, will be in compliance with all applicable laws, rules, regulations, requirements, guidelines, policies, economic or financial sanctions.

About AirSwap

AirSwap enables peer-to-peer trading on the Ethereum blockchain. Built on a decentralized protocol, traders can add or remove liquidity through a suite of trustless products that are easy to use and free. Our mission is to empower the world with frictionless trade.

Blog | Twitter | Discord | Developers | Makers | Reddit | Facebook | Linkedin | Subscribe | Support | Request a Feature | FAQ | Trade Now

Fluidity

Rebuilding Finance for a Frictionless World

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store