Requesting an order
This page is part of the typescript tutorial for creating your first COMIT-app, that builds two simple command-line application using the COMIT protocol to execute a Bitcoin to Ethereum atomic swap locally on your machine.
info
In this section we focus on the taker side and work on taker.ts
info
It is assumed that the maker application is finished at this stage, and running in a separate terminal.
In this section we fetch the order provided by a maker and check the rate.
Taker requests an Order
Similar to the maker, the comit-sdk provides provides a negotiation class for the taker as well, the TakerNegotiator
.
Knowing where to fetch order the taker can now initialise the TakerNegotiator
.
Similar to the maker he also has to provide his ComitClient
(initialised with the actor) for swap execution.
Additionally he has to provide the URL of the maker's order service.
The maker must share this information with the taker through some channel (e.g. Telegram group).
The taker can now request an order from the maker by defining a filter criteria. The criteria defines what the taker would like to trade.
The taker wants to receive one bitcoin, which he is willing to sel for ether at a minimum rate of 0.001
, hence he creates his criteria accordingly:
This is needed, because the taker might not know what the maker has to offer and if it is still available. In a more advanced implementation such kind of functionality would be provided by an orderbook.
With the criteria the taker can now request an order from the maker:
Note that TakerOrder
order returned by the TakerNegotiator
is specific to the taker. It combines the maker's order, specified through the Order interface, the taker's criteria and provides a take
function for the taker.
Let's log the rate offered by the maker:
Summary
At this stage your taker application should look similar to this:
info
In order to properly retrieve an order at the taker side, the maker application has to run at this stage!
If your maker app is not running you can start it with yarn maker
in a separate terminal.
Ensure that your maker app is running and then start the taker app with yarn taker
- it should print:
Since the taker only requests the offer and prints the rate, the swap execution is not yet triggered. Let's move on to the taker taking the order and triggering the swap execution!