AirSwap Maker Kit
Maker Kit includes tools and examples to help you get started on the AirSwap Network.
- Docs → https://docs.airswap.io/
- Website → https://www.airswap.io/
- Blog → https://blog.airswap.io/
- Support → https://support.airswap.io/
AirSwap is a peer-to-peer trading network for Ethereum (ERC20, ERC721) tokens. Using an Indexer smart contract, peers can find each other based on their mutual intent to trade specific tokens. Once found, peers exchange pricing information and settle trades on a Swap contract.
- Quotes are indicative prices and Orders are signed and executable for trading.
- Intent is an interest in trading including contact information, without pricing.
- Locators indicate how to connect to a peer. On AirSwap Instant, locators are web URLs.
git clone https://github.com/airswap/airswap-maker-kit cd airswap-maker-kit yarn install
Environment variables are loaded from a
.env file in the root directory. The following must be set:
ETHEREUM_ACCOUNT- The private key of an account to use for staking and trading.
ETHEREUM_NODE- The URL of an Ethereum node to connect to.
There is an example
.env-example that you can copy to
.env to start with.
To use an existing Ethereum account, set the
ETHEREUM_ACCOUNT in your
.env file. Otherwise create a random account using the
yarn utils:account script. Paste the generated private key into your
To use an existing Ethereum node, set the
ETHEREUM_NODE in your
.env file. Otherwise you can create a free account with INFURA. Navigate to https://infura.io/ to create an account and generate an API key and URL.
The Swap and Indexer contracts used by Maker Kit are specified within their respective packages,
@airswap/indexer in the AirSwap Protocols repository.
||Run maker tests|
||Start the maker|
||Create a token pair|
||Set an intent to trade|
||Unset an intent to trade|
||Approve a token for trading|
||Check a token approval|
||Get network addresses|
||Create a random account|
Helpful for Testing on Rinkeby
- ETH to pay for transactions - Faucet
- WETH for trading -
- DAI for trading -
- AST for staking -
0xcc1cbd4f67cceb7c001bd4adf98451237a193ff8Etherscan / Faucet
Quick Start: Quoting
The reference Node.js maker is configured to quote
WETH/DAI at price
0.1 on port
Test and start your maker
First run the tests to check that they pass.
$ yarn maker:test
All should clear. Now start up the maker to accept start accepting requests.
$ yarn maker:start info: Server now listening. (0.0.0.0:8080)
Get a quote from your maker
In another shell, run the
yarn peers:get script to test it out. Use the default values for everything but provide a
locator value of
http://0.0.0.0:8080/ to connect to your newly running maker.
$ yarn peers:get AirSwap: Get Quotes and Orders Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Rinkeby Select a kind (quote, order): (quote) Select a side (buy, sell): (buy) Query a locator (optional): http://0.0.0.0:8080/ Token to buy: (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea) Token to pay: (0xc778417e063141139fce010982780140aa0cd5ab) Amount to buy: (100) Got a Quote buy: 100 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea pay: 10 0xc778417e063141139fce010982780140aa0cd5ab price: 0.1
This succeeds because we have a locator in hand, the URL of your local webserver. However, if we do no thave a locator in hand, we need to use an indexer to find other trading parties.
Set your intent to trade
By default, your maker is running in isolation. Run
peers:get with default values, which will display
No peers found..
$ yarn peers:get
To be found, announce your maker to the world by setting your "intent to trade" on the indexer.
$ yarn indexer:set AirSwap: Set Intent to Trade Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Rinkeby Token address of signerToken (maker side): (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea) Token address of senderToken (taker side): (0xc778417e063141139fce010982780140aa0cd5ab) Web address of your server (URL): (http://10.0.0.169:8080) Amount of token to stake (AST): (0) Set an Intent signerToken: 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea senderToken: 0xc778417e063141139fce010982780140aa0cd5ab locator: http://10.0.0.169:8080 stakeAmount: 0 ...
The transaction will be mined and your locator is now on the indexer.
$ yarn indexer:get AirSwap: Get Locators Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Rinkeby Address of signerToken: (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea) Address of senderToken: (0xc778417e063141139fce010982780140aa0cd5ab) Number of locators to return: (10) 1. http://10.0.0.169:8080 ...
Get quotes from all makers (including yours)
Ensure your maker is still running.
Now run the same
peers:get with default values, which will display your quote.
$ yarn peers:get AirSwap: Get Quotes and Orders Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Select a network (rinkeby, mainnet): (rinkeby) Select a kind (quote, order): (quote) Select a side (buy, sell): (buy) Query a locator (optional): Token to buy: (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea) Token to pay: (0xc778417e063141139fce010982780140aa0cd5ab) Amount to buy: (100) ✓ Quote from http://10.0.0.169:8080 (cost: 10, price: 0.1)
Advanced: Staking and Trading
yarn indexer:enable script to enable staking on an Indexer. You'll use AirSwap Tokens (AST) to stake an intent to trade. On Rinkeby, use the Rinkeby AST Faucet to pick up some AST for staking.
$ yarn indexer:enable AirSwap: Enable Staking Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Select a network (rinkeby, mainnet): (rinkeby) This will approve the Indexer contract to stake your AST. ...
Tokens must be approved for trading on the Swap contract. This is a one-time transaction for each token. To approve the Swap contract to transfer your tokens, use the
yarn token:approve script for both WETH and DAI addresses above. You can check the approval status of any token with the
yarn token:check script.
- Locators - Makers must be accessible at public endpoints shorter than 32 characters in length including a URL scheme. For example
- CORS - Makers should run their servers with CORS enabled to accept connections from in-browser web applications like AirSwap Instant.
- Token Values - All token values are in the smallest indivisible units of a token (wei).
- Nonce Window - Each order is identified by a unique nonce. The "nonce window" is the time within which every order returned will include the same nonce. This can be configured to prevent overexposure.
- Trading ETH - Swap only supports tokens, not native ether (ETH). To trade ETH it must be wrapped (WETH).