# Getting Started

Welcome to Juungle API. We're glad you are here. If you have any questions please contact us on Telegram (opens new window).

# Introduction

Juungle is an instant, 0-conf exchange with partial custody, similarly to sideshift.ai (opens new window). We hold funds as short as possible to allow for completion of trades. In fact, we can provide your private keys for your deposit address if it helps in the development of your application! However, for most cases this isn't necessary.

# How does it work?

Juungle is able to prove an instant safe 0-conf experience through careful design of transaction dependency. Double spends are still possible, they just aren't profitable, and merely undo later actions in the graph. For example, if the NFT seller double spent, he would also undo the transaction that bought his NFT. If the NFT buyer double spent, the sale simply wouldnt go through, and a subsequent withdraw of BCH would also be eliminated.

Here is how the transaction flow looks:

graph

Because this design is based around Bitcoin and the UTXO model, it is very easy to integrate into your application. You can use your normal tools to send transactions, and only have a minimal api surface to implement for actions specific to the exchange (such as setting price).

# Setting Up for Selling on Exchange

To sell your tokens on the exchange, first you must create an account and login. Navigate to “Account” page. From here, click on “Wallet” and a pane will open showing you your deposit address.

Send your NFTs to the deposit address given above, they will be detected automatically (though give it a few seconds for the transaction to propagate). Then, perform the following :

  • userId={integer}
  • depositTxidSet=true
  • purchaseTxidUnset=true
  • withdrawTxidUnset=true
  • priceSatoshisUnset=true

You can see an example of this api call here (opens new window).

To get additional information about this route:

Get NFTs Endpoint

Next, you will need to set the price of these tokens. Using the above endpoint with different options (see documentation linked above) you can retrieve the nftId of your newly deposited tokens. These will be used in the set_price call.

By default when you deposit the price is unset and it will not be available for purchase. You must call an endpoint using the nftId you retrieved above. Using your JWT token, the nftId, and priceSatoshis you should call the /user/nfts/set_price route.

Set Price Endpoint

Once that is complete, your NFT will be available to purchase by others. If you would like to subscribe to this event, watch the blockchain for when your deposit NFT UTXO moves. This will be the sale, including your payment, unless you decide to withdraw it beforehand.

# Automated Purchasing

To find nfts you can use the generic get NFTs route. Make sure to include these query parameters:

  • depositTxidSet=true
  • purchaseTxidUnset=true
  • withdrawTxidUnset=true
  • priceSatoshisSet=true

Such as in this api call (opens new window).

To get additional information about this route, and other options you can provide to further filter:

Get NFTs Endpoint

Check for tokens you want to show. make sure to exclude those with purchaseHold set to true, these ones are in the process of being purchased and your Bitcoin Cash will be refunded. This property cannot be set during search query currently.

Once you have found a NFT you would like to purchase, your next step is to create a “purchase hold” - this gives you three minutes to perform your transaction and receive your NFT.

Pass the nftId received from the above call, along with an address to receive the NFT (or refund) at when making the following call:

Create Purchase Hold Endpoint

This will respond with an address and the exact amount of satoshis to send to it. You must send exactly the correct amount, or your order will be refunded and your Bitcoin Cash will be returned to your toAddress you provided during the creation of the purchase hold.

If successful, immediately a new transaction will be created sending the toAddress the NFT, as well as sending fee to exchange and the purchase amount to the seller.