1.5.4 • Published 2 months ago

@swap-coffee/sdk v1.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Installation

npm install @swap-coffee/sdk

Documentation can be found here.

Basic usage

Swapping assets using our SDK and TonConnect SDK

import { waitForRouteResults } from './transactions';

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 waitForRouteResults(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

1.5.4

2 months ago

1.5.3

3 months ago

1.5.2

3 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.4.0

6 months ago

1.3.0

8 months ago

1.2.1

10 months ago

1.2.0

12 months ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago