Skip to content
ahujsak edited this page Mar 6, 2019 · 2 revisions

Creating An Exchange Plugin

Each Exchange plugin is different but there are some common structural threads. A good way to get started is to copy either changenow.js or changelly.js in src/plugins and create your own .js file with the correct name

The main driver of your plugin is a central function makeYourPluginNamePlugin. Obviously change the name of the function.

Import that function into ./index.js by following the pattern already established in that file.

Key items to make sure you copy over and customize are

const swapInfo = {
  pluginName: '',
  displayName: '',
  quoteUri: '',
  supportEmail: ''
}
const dontUseLegacy = {
  DGB: true
}

// returns addresses 
async function getAddress (
  wallet: EdgeCurrencyWallet,
  currencyCode: string
): Promise<string> {
  const addressInfo = await wallet.getReceiveAddress({ currencyCode })
  return addressInfo.legacyAddress && !dontUseLegacy[currencyCode]
    ? addressInfo.legacyAddress
    : addressInfo.publicAddress
}

This block of code is for if your plugin uses legacy address types.

makePlugin function

This function will need to do the these basic processes. This may entail several calls to your api or just one.

  1. determine if your exchange supports the swap being requested.
  2. format the request in a way your API will understand and call to get quote
  3. Is the requested amount above or below any set limits you currently have on the api that does not make the swap feasible.
  4. If quote can be made, what are the miner fees etc.
  5. create a spend info
  6. call make swapInfoQuote

When referencing ChangeNow and Changelly you will see a distinct difference. Change now supports both estimate and exact quotes while changelly is only one type. So there is a lot less logic.

Integrating with our app

In order to test your plugin and have it published you will need to follow the instructions in the project for edge-react-gui.

NOTE: clone this repository and the edge-react-gui repository into the same folder. Do not change the names of the folders from their defaults. This will be important for testing.

Follow instructions in Gui Wiki for integration into app instructions

Testing

Anytime you want to make changes to your plugin and test in the app, the easiest way to do this is to leverage updot.

  1. Save your changes in your local branch of this repository
  2. In terminal, in the top level director of edge-react-gui npm run updot edge-exchange-plugins This will update the dependency.

Submit PR

Once your plugin is tested. submit a PR. You will need to also submit a PR for changes in edge-react-gui

Clone this wiki locally