2022-05-04 18:14:28 -04:00
# Haveno TypeScript Library
2021-04-21 15:52:40 -04:00
2022-11-21 13:11:28 -05:00
![GitHub Workflow Status ](https://img.shields.io/github/actions/workflow/status/haveno-dex/haveno-ts/build.yml?branch=master )
[![Twitter Follow ](https://img.shields.io/twitter/follow/HavenoDEX?style=social )](https://twitter.com/havenodex)
[![Matrix rooms ](https://img.shields.io/badge/Matrix%20room-%23haveno-blue )](https://matrix.to/#/#haveno:monero.social)
2022-05-04 18:14:28 -04:00
TypeScript library for using Haveno.
2021-04-21 15:52:40 -04:00
2022-05-06 08:23:57 -04:00
## Install
1. Start a Haveno daemon (see [installing.md ](https://github.com/haveno-dex/haveno/blob/master/docs/installing.md )).
2. Install haveno-ts in your project: `npm install haveno-ts`
2022-05-04 18:14:28 -04:00
## Sample code
2021-04-21 15:52:40 -04:00
2022-05-04 18:14:28 -04:00
```js
import { HavenoClient } from "haveno-ts";
2021-04-21 15:52:40 -04:00
2022-05-04 18:14:28 -04:00
// create client connected to Haveno daemon
const alice = new HavenoClient("http://localhost:8080", "apitest");
// use Haveno daemon
const balances = await alice.getBalances();
const paymentAccounts = await alice.getPaymentAccounts();
const myOffers = await alice.getMyOffers("ETH");
const offers = await alice.getOffers("ETH", "BUY");
const trade = await alice.takeOffer(offers[0].getId(), paymentAccounts[0].getId());
// disconnect client
await alice.disconnect();
```
## TypeDocs
2023-09-11 08:58:37 -04:00
See [TypeDocs ](https://haveno-dex.github.io/haveno-ts/classes/HavenoClient.HavenoClient.html ).
2022-05-04 18:14:28 -04:00
## Run tests
2023-09-11 08:58:37 -04:00
Running the [API tests ](./src/HavenoClient.test.ts ) is the best way to develop and test Haveno end-to-end. [`HavenoClient.ts` ](./src/HavenoClient.ts ) provides the client interface to Haveno's backend daemon.
2022-05-04 18:14:28 -04:00
2023-09-11 08:58:37 -04:00
You first need to start a local Haveno network which can be done manually or using docker.
### Start local Haveno network manually
2021-09-17 09:33:58 -04:00
2024-09-06 12:58:51 -04:00
This workflow is useful for local development of `haveno` and `haveno-ts`
2022-07-15 10:09:56 -04:00
1. [Run a local Haveno test network ](https://github.com/haveno-dex/haveno/blob/master/docs/installing.md ) and then shut down the arbitrator, user1, and user2 or run them as daemons, e.g. `make user1-daemon-local` . You may omit the arbitrator registration steps since it's done automatically in the tests.
2022-05-03 08:03:44 -04:00
2. Clone this project to the same parent directory as the haveno project: `git clone https://github.com/haveno-dex/haveno-ts`
2024-09-06 12:58:51 -04:00
3. Install `envoy` proxy from your package manager of choice, for example `brew install envoy` .
4. In a new terminal, start envoy with the config in haveno-ts/config/envoy.local.yaml: `envoy -c config/envoy.local.yaml`
2024-08-26 13:53:23 -04:00
5. In a new terminal, start the funding wallet. This wallet will be funded automatically in order to fund the tests.< br > For example: `cd ~/git/haveno && make funding-wallet-local` .
2023-09-11 08:58:37 -04:00
### Start local Haveno network with docker
2024-09-06 12:58:51 -04:00
Alternatively use this wokflow to develop `haveno-ts` or run tests with dockerized setup:
Start a local Haveno network with docker:
2023-09-11 08:58:37 -04:00
2024-09-06 12:58:51 -04:00
1. `cd ~/git/haveno-ts/docker`
2. `sudo docker-compose up` . This will start docker and initialize the network.
2023-09-11 08:58:37 -04:00
> **Docker Tips**
2024-05-12 08:04:38 -04:00
> * Stop: `sudo docker-compose stop`
2023-09-11 08:58:37 -04:00
> * Rebuild: `sudo docker-compose build`
2024-05-12 08:04:38 -04:00
> * Stop and delete contains: `sudo docker-compose stop`
2023-09-11 08:58:37 -04:00
### Run client tests
2023-02-23 09:38:41 -05:00
5. Install protobuf compiler [v3.20.3 ](https://github.com/protocolbuffers/protobuf/releases/tag/v3.20.3 ) for your system.
2021-11-25 08:28:39 -05:00
6. Download `protoc-gen-grpc-web` plugin and make executable as [shown here ](https://github.com/grpc/grpc-web#code-generator-plugin ).
2022-05-03 08:03:44 -04:00
7. `cd haveno-ts`
2021-11-23 20:11:12 -05:00
8. `npm install`
2023-09-11 08:58:37 -04:00
9. `npm run test -- --baseCurrencyNetwork=XMR_LOCAL` to run all tests or `npm run test -- --baseCurrencyNetwork=XMR_LOCAL -t "Can get the version"` to run tests by name.