@swap-coffee/sdk
v1.2.1
Published
SDK for swap.coffee DEX aggregator
Downloads
906
Maintainers
Readme
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:
Full example code can be found here
License
swap.coffee SDK is MIT licensed.
Copyright
swap.coffee © 2024