v2
You are reading v1 & v2. v1 and v2 are deprecated. They keep working and are still supported, but new integrations should use v3.

Getting started

Add a widget to your page with one script, an api-key and a target element.

A widget needs one script and one element. The script loads the widget from our CDN and initialises it with your api-key; the widget then renders itself into the element.

Step 1: Embed the script

<script lang="js">
  (function (btc, d, i, r, e, c, t) {
    btc[r] = btc[r] || function () {
      (btc[r].q = btc[r].q || []).push(arguments)
    };
    c = d.createElement(i);
    c.id = r; c.src = e; c.async = true;
    c.type = 'module'; c.dataset.btcdirect = '';
    t = d.getElementsByTagName(i)[0];
    t.parentNode.insertBefore(c, t);
  })(window, document, 'script', 'btcdirect',
    'https://cdn.btcdirect.eu/fiat-to-coin/fiat-to-coin.js'
  );

  btcdirect('init', { token: 'API_KEY' });
</script>

Step 2: Set your api-key

Replace API_KEY with the api-key BTC Direct gave you. It identifies you as a partner. If you do not have one yet, ask your account manager.

Init options

tokenrequired

string

Your api-key.

selectoroptional

string

CSS selector of the element the widget renders into. Default .btcdirect-widget.

localeoptional

string

Language and number formatting, e.g. en-GB or nl-NL. Default en-GB.

themeoptional

string

Colour theme. Default light.

One oflightdark

debugoptional

boolean

Extra logging in the browser console. Recommended while you build. Default false.

hideFooteroptional

boolean

Hides the "Secured by BTC Direct" bar along the bottom. Default false.

Each widget takes a few options of its own; its page lists them.

Step 3: Pick the widget

The script URL decides which widget loads:

  • Buy: https://cdn.btcdirect.eu/fiat-to-coin/fiat-to-coin.js
  • Sell: https://cdn.btcdirect.eu/coin-to-fiat/coin-to-fiat.js
  • Transaction history: https://cdn.btcdirect.eu/transaction-history/transaction-history.js
  • Onboarding: https://cdn.btcdirect.eu/onboarding/onboarding.js
  • DCA: https://cdn.btcdirect.eu/dollar-cost-average/dollar-cost-average.js

Sandbox is coming soon

A sandbox build of the widgets, against our sandbox environment, is coming soon. Until then the URLs above are production: orders placed through them are real.

Step 4: Add the target element

The widget renders into the element matching selector, by default one with the class btcdirect-widget:

<body>
  <div class="btcdirect-widget"></div>
</body>

Optional: add the stylesheet

A stylesheet gives the widget a responsive layout and the BTC Direct look. Add it to your page's <head>, matching the widget you load:

<head>
  <link href="https://cdn.btcdirect.eu/fiat-to-coin/fiat-to-coin.css" rel="stylesheet" />
</head>

Swap fiat-to-coin for coin-to-fiat, transaction-history, onboarding or dollar-cost-average for the other widgets. The styling starts from the btcdirect-widget-container class, so if you give the target element your own identifier, add it beside the class rather than replacing it:

<div class="btcdirect-widget" id="widget-target"></div>

Configuring the widget with method calls

Beyond init, a widget is configured with method calls, written straight after init in the same script:

btcdirect('init', { token: 'API_KEY' });
btcdirect('currencies', { crypto: 'BTC', fiat: 'EUR' });

They are read once, in order, when the widget loads; when two calls set the same thing, the later one wins. Each widget's pages list the calls it takes.

A few calls answer something that happens while the customer is using the widget, and you make those whenever it happens: the wallet and transaction confirmations on the buy and sell pages, and these two, which every widget takes:

btcdirect('locale', { locale: 'nl-NL' }); // switch language
btcdirect('logout');                       // sign the customer out

iFrames

The widgets do not run in an iFrame. See common questions for why.