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

Common questions

More than one widget on a page, CORS errors, and iFrames.

More than one widget on a page

Give each widget its own name and its own target element. The name is the fourth argument of the snippet, and it is also the function you call:

<script lang="js">
  // The snippet from "Getting started", named buyWidget.
  (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', 'buyWidget',
    'https://cdn.btcdirect.eu/fiat-to-coin/fiat-to-coin.js'
  );
  buyWidget('init', { token: 'API_KEY', selector: '.buy-widget' });

  // The same snippet again, named sellWidget.
  (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', 'sellWidget',
    'https://cdn.btcdirect.eu/coin-to-fiat/coin-to-fiat.js'
  );
  sellWidget('init', { token: 'API_KEY', selector: '.sell-widget' });
</script>

<div class="widgets">
  <div class="buy-widget"></div>
  <div class="sell-widget"></div>
</div>

<style>
  .widgets { display: grid; grid-template-columns: 1fr; gap: 2rem; }
  @media screen and (min-width: 700px) {
    .widgets { grid-template-columns: 1fr 1fr; }
    .widgets .btcdirect-widget-container { width: 100%; }
  }
</style>

CORS errors

A CORS error from the widget's calls is usually your page's referrer policy: the calls need a Referer header, and it must not be empty. Packages such as helmet and nuxt-helmet can strip it; enable the referrer in their settings.

Do the widgets work in an iFrame?

No, and they will not. The widgets are built to run directly in your page: a payment flow needs an environment we fully control, which an iFrame on someone else's page is not.