---
title: Getting started
description: 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

```html
<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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `token` | string | required | Your api-key. |
| `selector` | string | optional | CSS selector of the element the widget renders into. Default .btcdirect-widget. |
| `locale` | string | optional | Language and number formatting, e.g. en-GB or nl-NL. Default en-GB. |
| `theme` | string | optional | Colour theme. Default light. |
| `debug` | boolean | optional | Extra logging in the browser console. Recommended while you build. Default false. |
| `hideFooter` | boolean | optional | 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](https://partner.btcdirect.eu/v2/sandbox.md) 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`:

```html
<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:

```html
<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:

```html
<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:

```js
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](https://partner.btcdirect.eu/v2/widget/buy/events.md) and [sell](https://partner.btcdirect.eu/v2/widget/sell/parameters.md)
pages, and these two, which every widget takes:

```js
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](https://partner.btcdirect.eu/v2/widget/common-questions-and-issues.md) for why.
