The Banxa JavaScript SDK provides a lightweight alternative to manually constructing referral URLs. Include a single script tag and use the Banxa class to trigger redirect or iFrame checkout from any button or event in your page.
Add the following loader script to your page. It asynchronously loads the SDK and calls your yourOnLoadFunction callback when ready.
!function(callback){
var b = document.createElement('script');
b.type = "text/javascript";
b.async = true;
b.src = "https://sdk.banxa.com/js/banxa-sdk-latest.js";
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(b, x);
if (callback) { b.addEventListener("load", function() { callback() }) }
}(yourOnLoadFunction);Create an instance of Banxa with your partner name. Use the second argument to select sandbox or production.
// Production
const banxa = new Banxa('your-partner-name');
// Sandbox
const banxa = new Banxa('your-partner-name', 'sandbox');Replace your-partner-name with the partner subdomain provided by Banxa (e.g., binance, metamask).
Open the Banxa checkout in a new browser tab when a button is clicked.
banxa.redirect('#redirect', {
fiatType: 'AUD',
coinType: 'BTC',
fiatAmount: 500,
walletAddress: '3Hiy7HuFcqwkgERyfRSwEHqrwSwTirm8zb',
theme: 'dark'
});<button id="redirect">Buy crypto</button>The first argument (#redirect) is a CSS selector for the element that triggers the checkout on click.
Inject an iFrame into a container element in your page.
banxa.iframe(
'#iframeButton', // trigger element selector
'#iframeTarget', // container element selector
{
fiatType: 'AUD',
coinType: 'BTC',
fiatAmount: 200,
walletAddress: '3Hiy7HuFcqwkgERyfRSwEHqrwSwTirm8zb'
},
'800px', // optional width (pass false to omit)
'400px' // optional height (pass false to omit)
);<button id="iframeButton">Open checkout</button>
<div id="iframeTarget">
<!-- iFrame is injected here -->
</div>All referral URL parameters are supported as keys in the options object passed to redirect() and iframe().
- The SDK generates a referral URL from the options you provide and opens it via redirect or iFrame — it does not make server-to-server API calls.
- For server-to-server order creation (with webhooks, order IDs, and KYC sharing), use the API integration instead.