@swap-coffee/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

swap.coffee logo

SDK for swap.coffee DEX aggregator

npm License documentation

Installation

npm install @swap-coffee/sdk

Documentation can be found here.

Basic usage

Swapping assets using our SDK and TonConnect SDK

const connector = await setupTonConnect();
const routingApi = new RoutingApi();

const assetIn: ApiTokenAddress = {
  blockchain: 'ton',
  address: 'native', // stands for TON
};
const assetOut: ApiTokenAddress = {
  blockchain: 'ton',
  address: 'EQCl0S4xvoeGeFGijTzicSA8j6GiiugmJW5zxQbZTUntre-1', // CES
};

const input_amount = 5; // 5 TON

const route = await routingApi.buildRoute({
  input_token: assetIn,
  output_token: assetOut,
  output_amount: 200, // desired amount of output token
});

const transactions = await routingApi.buildTransactionsV2({
  sender_address: connector.account?.address!!,
  slippage: 0.1,
  paths: route.data.paths, // note: use route.data here
});


let messages = [];

for (const transaction of transactions.data.transactions) {
  messages.push({
    address: transaction.address,
    amount: transaction.value,
    payload: transaction.cell,
  });
}

await connector.sendTransaction({
  validUntil: Date.now() + 5 * 60 * 1000,
  messages: messages,
});

const results = await waitForTransactionResults(transactions.data.route_id, routingApi);

And here is our transaction:

img.png

Full example code can be found here

License

swap.coffee SDK is MIT licensed.

Copyright

swap.coffee © 2024

Package Sidebar

Install

npm i @swap-coffee/sdk

Homepage

swap.coffee

Weekly Downloads

128

Version

1.2.1

License

MIT

Unpacked Size

429 kB

Total Files

24

Last publish

Collaborators

  • catcoderr