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 ZEIT Now.

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.

Deploying with ZEIT Now

This is probably the easiest part of the tutorial, because ZEIT makes deployment so easy. Simply run the following command inside of airswap-zeit-example/

$ 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 https://maker.<your zeit username>.now.sh

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 now.json to something shorter, or using a shorter ZEIT 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 .env file that you created in the airswap-zeit-example directory and copy the ETHEREUM_ACCOUNT 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.

Using the Indexer

At the end of Part 1, we queried our maker locally by pasting our localhost:3000 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

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 airswap indexer:get command to view the current state of the list.

airswap indexer:set

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).

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 🎉

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 ZEIT 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

Graham Perich

Written by

👨‍💻 Software Engineer - building the future of trade @AirSwap

Fluidity

Fluidity

Rebuilding Finance for a Frictionless World

More From Medium

More from Fluidity

More from Fluidity

The Dark Side of AWS Lambda

1.5K

More from Fluidity

More from Fluidity

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade