<aside> ⚠️
Our B2B SDK uses require("crypto") under the hood, so please make sure it is available in the execution context.
</aside>
import { B2BSDK } from './sdk-node';
// You can get those variables at the B2B section of your partner account
const sdk = new B2BSDK({
domain: 'b2b.swapduck.space',
partnerId: 'stinky-duck-HbMytL',
publicKey: 'changeme',
privateKey: 'changeme',
});
async function testSDK(sdk: B2BSDK) {
try {
await sdk.test() // This will call some endpoints on our side
} catch (err) {
console.error(err, 'B2B SDK not operational')
}
}
<aside> ℹ️
Our XML file is based on the BestChange XML format. Currencies not present on BestChange will have IDs based on their name and network.
</aside>
const xml: string = await sdk.getXML('my-personal-xml');
// drop the .xml extension at the end ^
// ex.: /rates/xml/my-personal-xml.xml -> my-personal-xml
type Currency = {
id: {
name: string;
network: string;
};
createdAt: number;
isActive: boolean;
bestchangeId: string;
precisionDecimals: number;
logoUrl: string;
type: string;
isMemo: boolean;
description?: string;
};
type ListCurrenciesResponse = {
result: 'success' | 'error';
data: {
currencies: Currency[];
};
};
const currencies: ListCurrenciesResponse = await sdk.listCurrencies()
type PartnerEstimationResponse = {
result: 'success' | 'error';
data: {
amountLeft: string;
amountRight: string;
amountLeftUsdt: string;
amountRightUsdt: string;
exchangeStrategyId: string;
appliedNetworkFee: string;
hash: string;
minAmount: string;
maxAmount: string;
quotes: {
sellQuote: {
baseValue: string;
quoteValue: string;
};
buyQuote: {
baseValue: string;
quoteValue: string;
};
}
};
};
const estimation: PartnerEstimationResponse = await sdk.estimateRate({
amountLeft: '1',
currencyLeftName: 'BTC',
currencyLeftNetwork: 'BTC',
currencyRightName: 'USDT',
currencyRightNetwork: 'TRC20'
});