The Haveno Dart client is available on pub.dev haveno client repo and allows you to easily interact with the Haveno network via an easy to use client that sits over the complex gRPC and Protobuf communication. This guide will walk you through setting up a Dart environment, using the Haveno Dart client to write trading bots, or even developing your own custom interface. The interface used by the Haveno app itself can be accessed through this client.
Prerequisites
Before you can start using the Haveno Dart client, you'll need to have Dart and some development tools properly installed. Here's how to get everything set up.
Setting up a Dart Environment
-
Install Dart SDK:
- Visit the Dart SDK website to download and install the latest version.
- For macOS, you can install Dart using Homebrew:
brew tap dart-lang/dart brew install dart
- For Linux, follow the official guide on the Dart website.
- For Windows, download the Dart SDK installer from the Dart website.
-
Install Visual Studio Code:
- Download and install Visual Studio Code.
- Open VSCode and install the Dart extension:
- Go to the Extensions tab (left sidebar).
- Search for "Dart" and click Install.
-
Set Up a Dart Project:
- Open a terminal window, navigate to the folder where you want to create the project, and run the following command:
dart create haveno_project
- Open the folder in VSCode:
code haveno_project
- Open a terminal window, navigate to the folder where you want to create the project, and run the following command:
-
Add Haveno as a Dependency:
- Open your
pubspec.yaml
file and add the Haveno package as a dependency:dependencies: haveno: ^3.0.1 # replace with the latest version
- Run
flutter pub get
ordart pub get
to install the package.
- Open your
Using the Haveno Dart Client
Now that your environment is set up, let's walk through how to start using the Haveno Dart client to interact with the Haveno network.
Basic Usage Example
Here’s how you can set up the Haveno client and begin interacting with the network. This example demonstrates connecting to the Haveno server and performing some basic operations.
import 'package:haveno/haveno.dart';
void main() async {
// Create the singleton
final havenoChannel = havenoChannel();
// Create the connection to the daemon instance
var channel = havenoChannel.connect(
host: 'localhost', // Replace with daemon host
port: 18081, // Replace with daemon port
password: "some_secure_password" // Optional
);
// Example: Fetching market offers
List<OfferInfo> _offers = [];
final offersService = OffersService();
_offers = offersService.getOffers();
// Example: Placing a trade offer
OfferInfo? _offer;
final offersService = offersService OffersService()
var _offer = offersService.postOffer(
direction: TradeDirection.BUY,
amount: 1000000, // Amount in atomic units
price: 0.015,
asset: 'XMR',
... etc etc
);
print('Created offer with ID: $offer.offerId');
}
You can use this code as a starting point for more complex operations, such as:
- Fetching the current list of active trades
- Executing trades
- Monitoring trade status and updates
- Developing automated trading bots
Developing Your Own Interface
The Haveno Dart client provides all the necessary tools for you to create your own decentralized exchange interface. This means you can build custom UIs or even extend existing ones. Our own Haveno app utilizes the same interface that this Dart client offers.
Some key areas to focus on:
-
Fetching Market Data:
You can query the Haveno server for available markets, prices, and trading volumes to build real-time trading charts. -
Trading Functions:
The client allows users to create and manage trade offers, monitor trades, and interact with market participants. -
Custom Features:
You can extend the existing client to add features specific to your interface or bot, such as custom notifications, trade analytics, or portfolio management.
The full Haveno Dart API is available on the pub.dev documentation section.
Setting up Example Code
In your lib/main.dart
, you can include the examples mentioned and tweak them to suit your trading strategy or interface.
Conclusion
The Haveno Dart client is a powerful tool for developers looking to create decentralized exchange solutions, trading bots, or custom applications for the Haveno network. Whether you're interested in writing automated scripts or developing a full-fledged interface, this client provides everything you need to interact with Haveno via gRPC and Protobuf.
To get started, install the client, set up your environment, and begin exploring the many possibilities.
You can find more details about the Haveno Dart client on pub.dev. Feel free to provide your own examples below, or reach out if you need further assistance in implementing specific features!
Member discussion