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
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 Maker Kit includes a script to automate token approvals, so let’s take care of that now.
On the command line, navigate to the
airswap-maker-kit repo that you cloned down in Part 1. Then, copy the
.env file that you created in the
airswap-maker-kit-examples directory and duplicate it in
It should look like this:
Now we’re ready to run the token approval script.
$ yarn 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.
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.
Again, navigate to the
airswap-maker-kit directory if not already there.
First, approve the indexer to stake AST
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
yarn indexer:get command to view the current state of the list.
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.
More about AirSwap
- Subscribe to the Fluidity Blog
- Request and upvote new features on AirSwap
- Catch up on AirSwap product updates
- Follow AirSwap on Facebook, Twitter, LinkedIn, Instagram, and YouTube
- Visit our AirSwap Developer Tools for the latest AirSwap tutorials, docs, and updates
- Join us on our Discord and Telegram
- Subscribe to AirSwap’s subreddit