Creating a simple order service
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 maker side and work on maker.ts
In this section we use the comit-js-sdk negotiation classes to create a simple HTTP order service where the maker can publish orders. This tutorial does not tackle the problem of "finding a trading partner".
Creating a simple HTTP order service
We start with the maker again (in maker.ts
).
For the maker we use the MakerNegotiator
class of the comit-sdk to create a simple order HTTP-server using nodejs-express.
After the negotiation the MakerNegotiator
will trigger the execution of the swap, hence it has to be initialised with the necessary execution information:
- The
ComitClient
used by the maker to communicate with his cnd node for executing the swap. - The execution parameters of the maker provided for the taker (so they can reach an agreement on how to execute the swap):
- Connection information to the maker's cnd (
peerId
andaddressHint
). - The
expiry
for thealpha
(Ethereum) andbeta
(Bitcoin) ledger. - The configuration for the repective ledger (the taker should know on e.g. which network the maker wants to execute the swap).
- Connection information to the maker's cnd (
The ComitClient
was already initialised through the actor initialisation in the previous section.
Let's define the execution parameters that the maker is suggesting for his swaps:
For calculating the expiry timestamps we use the moment
module. You will have to add it to your dependencies
:
In addition to the parameters mentioned above, the maker is also providing TryParams
for the execution.
The swap's status is handled inside of cnd.
The comit-SDK is polling cnd for actions (e.g. fund, redeem, refund) that become available for a swap.
Once an action becomes available the action can be executed using the wallets provided in the comit-SDK.
The TryParams
define how often the ComitClient
will poll the swap status from cnd and a maximum timeout.
Now we have all the parameters for the MakerNegotiator
assembled and can create an instance:
Through the MakerNegotiator
the maker is capable of creating an Order
.
To make those orders available to the taker, the maker has to expose the MakerNegotiator
's HttpService
:
Summary
At this stage you maker.ts
file should look simliar to this:
When running yarn maker
it prints: