Skip to main content
Time to read: 1 min

RBTC Flyover - SDK Integration

The RBTC Flyover SDK streamlines integration between client applications and the Flyover Protocol. This easy-to-use JavaScript/TypeScript toolkit provides configuration options for Liquidity Providers (LPs) and custom network setups for connecting to Rootstock.

Here you can find step-by-step guides on how to integrate and perform basic operations using the SDK.

Prerequisites

The following are the minimum requirements and dependencies required for integrating the Flyover SDK.

Hardware Requirements

Networks

Tip

To set up a Rootstock node (RSKj). Read the Installation Guide for different operating systems or use the Reproducible build.

Getting Testnet Funds

You can get test BTC funds on Coinfaucet. To get test funds for RBTC, use the Rootstock Faucet. To get a legacy wallet address for use on Testnet, consider using an Electrum Bitcoin wallet.

Contract Addresses

Find a list of contract addresses for the Liquidity Bridge Contract (LBC), mainnet, and testnet addresses.

Installation

To install the Flyover SDK. See the different installation types.

npm install @rsksmart/flyover-sdk

Usage

Import the Flyover SDK into project:

import { Flyover } from '@rsksmart/flyover-sdk';

Initialise the SDK

const flyover = new Flyover({ 
network: 'Regtest',
captchaTokenResolver: async () => Promise.resolve(''),
})

This creates a new instance of the Flyover and sets the network to "Regtest". See available network options.

catpchaTokenResolver

There is a mandatory parameter called catpchaTokenResolver, this is because some LPs might want to enforce only human-generated quotes to provide their services.

Configuring the SDK

Connect to Rootstock

Note that you can provide a Regtest environment URL. For insecure custom environment URLs, it is required to allow for insecure connections.

const flyover = new Flyover({
network: 'Regtest',
customRegtestUrl: 'http://localhost:8080',
allowInsecureConnections: true
})

Peg in Operations

A Peg-in is the process of converting BTC to RBTC.

Choose a Liquidity Provider (LP)

First, you need to choose the LP that will be providing the service to advance the RBTC, in order to do this, you should fetch the LPs list and select one of them by using the useLiquidityProvider method. Before making this selection you may want to present the options to the final users so they can choose based on the delivery time or fees.

const providers = await flyover.getLiquidityProviders()
flyover.useLiquidityProvider(providers.at(0))

Request a Quote

Now, you can interact with the SDK and perform basic queries, for example, request a quote.

    const quotes = await flyover.getQuotes({ /* QuoteRequest data... */ })
const acceptedQuote = await flyover.acceptQuote(quotes.at(0))

Get Quotes

Quotes act as a contract between a user and a liquidity provider. The getQuote operation creates a quote that defines the terms of the service that the LP will provide to a given user, each quote is unique so if the same request is done multiple times it will result in different quotes. The PeginQuoteRequest is used to compute a specific quote.

Example Request:

flyover.useLiquidityProvider(provider)
await flyover.getQuotes(quoteRequest)

This sets the provider for the Flyover instance using the useLiquidityProvider method. This method also sets the provider whose LPS will be used to get/accept quotes.

Accept a quote

This accepts a specific peg-in quote. Meaning that the user is expressing commitment to pay for that quote according to the terms negotiated with the LP through the quote specification. Here, the user is provided with the address that they need to transfer his BTC to.

flyover.useProvider(provider)
const quotes = await flyover.getQuotes(quoteRequest)
await flyover.acceptQuote(quotes[0])

Peg out Operations

This is the process of converting RBTC to BTC. See Mainnet Guide.

Select a Liquidity Provider

In the same way we need to select an LP to perform PegIn operations, we need to select one to perform PegOut operations. It’s important to remark that if you already selected an LP to perform a PegIn you don’t need to select it again for a PegOut.

 const providers = await flyover.getLiquidityProviders()
flyover.useLiquidityProvider(providers.at(0))

Get Peg out Quote

This operation gets the available peg-out quotes for the given parameters. Instead of a QuoteRequest, this method requires a PegOutQuoteRequest.

flyover.useProvider(provider)
await flyover.getPegoutQuotes(quoteRequest)

Accept Peg out Quote

This method accepts a specific peg out quote and returns a promise with an AcceptedPegoutQuote, an accepted quote with confirmation data. Instead of a deposit address, the acceptPegoutQuote method returns the address of the liquidity bridge contract where the user needs to execute the “depositPegout” function (this can be done with the SDK as well).

flyover.useProvider(provider)
const quotes = await flyover.getPegoutQuotes(quoteRequest)
const acceptedQuote = await flyover.acceptPegoutQuote(quotes[0])
const txHash = await flyover.depositPegout(quotes[0], acceptedQuote.signature, FlyoverUtils.getQuoteTotal(quotes[0]))
Tip

For peg outs, deposits (RBTC) can be made directly from the SDK, using a connected wallet.

API Reference

The API reference provides comprehensive documentation of all Flyover SDK functions and functionalities with detailed explanations and code examples. See the Flyover SDK documentation.

Troubleshooting

Encountering difficulties with the SDK setup, LPS configuration, or specific Flyover issues? Join the Rootstock Discord community for expert support and assistance. Our dedicated team is ready to help you resolve any problems you may encounter.

Last updated on by Owanate Amachree