These docs are for v3. Click to read the latest docs for v4.

Building a Compliant Swap Service

Use Wyre to build a compliant crypto swap service

You can quickly create a compliant crypto swap service using Wyre's Wallet and Transfers APIs. This service will be able swap between any of the cryptocurrency pairs offered by Wyre.

๐Ÿ“˜

Contents:

  1. Business Account Setup
  2. Creating Wallets
  3. Swap Transfer
  4. Deposit External Funds
  5. Withdrawing Funds
  6. Transfer Status

Wyre wallets are white label API driven crypto wallets that you can easily integrate into your app or platform.

1. Business Account Setup

๐Ÿ“˜

Business Account Setup Notes:

800

2. Creating Wallets

Your app or platform can generate Wyre wallets on the fly. Use the Create Wallet endpoint to create wallets for your users.

You can create DEFAULT,ENTERPRISE or SAVINGS wallet types.

  • DEFAULT wallets are used for individuals.
  • ENTERPRISE wallets are used to represent control by a business.
  • SAVINGS wallets are used for individuals and businesses who wish to receive interest on their crypto holdings.

When creating a wallet you will need to take note of the wallet id and the depositAddresses node. You will reference the wallet id when making internal transfer swaps. The depositAddresses: BTC and ETH will be referenced when your users fund the Wyre wallet from external crypto wallets. Note that the ETH address supports all of Wyre's ERC20 tokens.

{
    "owner": "account:AC_Y22XXXXXXXX",
    "pusherChannel": "d89ecb3deae49a753c0df3a2166f46dd",
    "srn": "wallet:WA_XXXXXXXX1",
    "status": null,
    "createdAt": 1605818017849,
    "balances": {},
    "notes": null,
    "depositAddresses": {
        "BTC": "mfbhWCN9tevTQgWKgHhjbHgESqiGXyDUkH",
        "ETH": "0x48093f4de78b4b26e3a2b90bb2a5cf92883570c3"
    },
    "totalBalances" : {
        "BTC" : 0,
        "ETH" : 0,
    },
    "availableBalances" : {
        "BTC" : 0,
        "ETH" : 0
    },
    "callbackUrl": null,
    "name": "random-uid-value-from-your-app-2",
    "id": "WA_XXXXXXXX1",
    "type": "DEFAULT",
    "callbackUrl" : "https://your.website.io/callback",
    "notes" : "Notes about the user"
}

3. Crypto Swap Transfers

Wyre wallets are identified with a unique identifier i.e. "WA_XXXXXXX1". Note that for swaps the source and dest will reference the same wallet identifier belonging to the user.

Example: Swap transfer to the same wallet
{  
     "source":"wallet:WA_XXXXXXXX1",
     "sourceCurrency":"BTC",
     "destCurrency":"ETH", 
     "sourceAmount":"0.015",
     "dest":"wallet:WA_XXXXXXXX1",
     "message": "Crypto Swap",
     "autoConfirm":true  
 }

Example shows the Create Transfer endpoint data.

4. How to Get External Funds Into Wyre Wallets

Your users will need to transfer crypto funds into your platform's generated Wyre wallets. This requires pulling in one or both of the depositAddresses as described in Step 3. You can also fetch the wallet details using the Lookup Wallet endpoint.

"depositAddresses": {
        "BTC": "mfbhWCN9tevTQgWKgHhjbHgESqiGXyDUkH",
        "ETH": "0x48093f4de78b4b26e3a2b90bb2a5cf92883570c3"
    },

You can then display the deposit addresses to your users as a QR code or plain text. Your user's can then scan or copy/paste the deposit address to make a deposit payment from an external crypto wallet.

5. How to Complete a Trade Back to Your Wallets

Using the Create Transfer endpoint, you can withdraw crypto funds to external wallets. The example below shows how the dest references the user's external crypto wallet address. Note the SRN ethereum is concatenated to the address.

Example: Transfer funds to an external wallet
{  
     "source":"wallet:WA_XXXXXXXX1",
     "sourceCurrency":"ETH",
     "destCurrency":"ETH", 
     "sourceAmount":"0.534",
     "dest":"ethereum:0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
     "message": "External Transfer",
     "autoConfirm":true  
 }

The Create Transfer endpoint returns a Transfer Id. This Id can be used to check the status of a transfer.

6. Checking Transfer Status

The returned Transfer Id can be used to look up a transfer by using the Get Transfer endpoint. The returned data provides information regarding fees, status and blockchain transaction hash.

{
  "owner": "account:AC_XXXXXXXX1",
  "reversingSubStatus": null,
  "source": "wallet:WA_XXXXXXXX1",
  "pendingSubStatus": null,
  "status": "COMPLETED",
  "reversalReason": null,
  "createdAt": 1603824914000,
  "sourceAmount": 2.02,
  "destCurrency": "ETH",
  "sourceCurrency": "ETH",
  "statusHistories": [
    {
      "id": "QXXXXXXXX",
      "transferId": "TF_XXXXXXXX1",
      "createdAt": 1603824935000,
      "type": "OUTGOING",
      "statusOrder": 0,
      "statusDetail": "Initiating Transfer",
      "state": "INITIATED",
      "failedState": null
    },
    {
      "id": "BXXXXXXXX",
      "transferId": "TF_XXXXXXX1",
      "createdAt": 1603824935000,
      "type": "OUTGOING",
      "statusOrder": 200,
      "statusDetail": "Processing Exchange",
      "state": "PENDING",
      "failedState": null
    },
    {
      "id": "9XXXXXXXX",
      "transferId": "TF_XXXXXXXX1",
      "createdAt": 1603824936000,
      "type": "OUTGOING",
      "statusOrder": 400,
      "statusDetail": "Processing Deposit",
      "state": "PENDING",
      "failedState": null
    },
    {
      "id": "TXXXXXXXX",
      "transferId": "TF_XXXXXXXX1",
      "createdAt": 1604346618000,
      "type": "OUTGOING",
      "statusOrder": 5100,
      "statusDetail": "Transfer Completed",
      "state": "COMPLETED",
      "failedState": null
    }
  ],
  "blockchainTx": {
    "id": "TR_XXXXXXXX1",
    "networkTxId": "8ba2f644f71b2eaa5edd8e421df4a0b902e...",
    "createdAt": 1604343572000,
    "confirmations": 1,
    "timeObserved": 1604344752000,
    "blockTime": 1604346566000,
    "blockhash": "0x0000000000000000000299574cd707c36...",
    "amount": 0.534,
    "direction": "OUTGOING",
    "networkFee": 0.00066185,
    "address": "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
    "sourceAddress": null,
    "currency": "ETH",
    "twinTxId": null
  },
  "expiresAt": 1603825514000,
  "completedAt": 1604346618000,
  "cancelledAt": null,
  "failureReason": null,
  "updatedAt": 1604346617000,
  "exchangeRate": 0.00007264620000000001,
  "destAmount": 0.00014529,
  "fees": {
    "ETH": 0,
    "USD": 0
  },
  "totalFees": 0.00066185,
  "customId": "xxxxxxx-1111-77777-99999-1234567896",
  "dest": "ethereum:0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
  "message": null,
  "id": "TF_XXXXXXXX1"
}

Example shows the Get Transfer endpoint data.