Discovery
To find servers that support a token pair, clients call the getURLsForToken function on the Registry contract for each token and then intersect the results. For example, if the resulting URLs for token A are [maker1.com, maker2.com] and for token B are [maker2.com, maker3.com] then the only server supporting swapping token A for B is maker2.com.
See getURLsForToken on the Registry contract:
1
function getURLsForToken(address token) external view returns (string[] memory urls);
Copied!
Check deployments for latest contract addresses for Registry.

Fetching URLs via CLI

Ensure the AirSwap CLI is installed.
1
$ yarn global add airswap
Copied!
Use airswap chain to set your chain to Rinkeby or Mainnet.
1
$ airswap chain
2
AirSwap CLI 1.6.1 — https://airswap.io/
3
4
set the active ethereum chain
5
6
Current chain: 4 (RINKEBY)
7
8
New chain: (1=mainnet, 4=rinkeby, 5=goerli, 42=kovan, 56=binance): (4) 1
9
10
Set active chain to MAINNET.
Copied!
Use registry:get to fetch server URLs for a token pair.
1
$ airswap registry:get
2
AirSwap CLI 1.6.1 — https://airswap.io/
3
4
get urls from the registry MAINNET
5
6
Registry 0x8F9DA6d38939411340b19401E8c54Ea1f51B8f95
7
8
Token pair (e.g. WETH/USDT): DAI/WETH
9
10
Server
11
----------------------------------------
12
https://maker.example.com/
Copied!

Example: Take an Order

Try airswap order:get with a server URL from the previous command.

TypeScript

Using the Registry library from @airswap/protocols can return Server objects that implement the RFQ API.
1
import { Registry } from '@airswap/protocols'
2
const servers = await new Registry(chainId, provider).getServers(
3
signerToken,
4
senderToken,
5
)
Copied!
Calling the Registry directly using ethers
1
import { ethers } from 'ethers'
2
import { chainNames } from '@airswap/constants'
3
import * as RegistryContract from '@airswap/registry/build/contracts/Registry.sol/Registry.json'
4
import * as registryDeploys from '@airswap/registry/deploys.js'
5
const RegistryInterface = new ethers.utils.Interface(
6
JSON.stringify(RegistryContract.abi),
7
)
8
9
new ethers.Contract(
10
registryDeploys[chainId],
11
RegistryInterface,
12
ethers.getDefaultProvider(chainNames[chainId].toLowerCase()),
13
)
14
15
const baseTokenURLs = await this.contract.getURLsForToken(baseToken)
16
const quoteTokenURLs = await this.contract.getURLsForToken(quoteToken)
17
18
const serverURLs = baseTokenURLs.filter((value) =>
19
quoteTokenURLs.includes(value),
20
)
Copied!

Example: Take an Order

1
import { Registry, Light } from '@airswap/libraries'
2
import { chainNames } from '@airswap/constants'
3
4
const provider = ethers.getDefaultProvider(chainNames[chainId].toLowerCase())
5
6
const servers = await new Registry(chainId, provider).getServers(quoteToken, baseToken);
7
8
const order = servers[0].getSignerSideOrder(
9
baseTokenAmount,
10
quoteToken,
11
baseToken,
12
wallet.address
13
)
14
15
const tx = await new Light(chainId, provider).swap(order);
Copied!
Last modified 2d ago