@folks-router/js-sdk 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @folks-router/js-sdk
|
|
2
|
+
|
|
3
|
+
The official JavaScript/TypeScript SDK for Folks Router DEX aggregator.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install using your package manager of choice.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# npm
|
|
11
|
+
npm install @folks-router/js-sdk
|
|
12
|
+
|
|
13
|
+
# yarn
|
|
14
|
+
yarn add @folks-router/js-sdk
|
|
15
|
+
|
|
16
|
+
# pnpm
|
|
17
|
+
pnpm add @folks-router/js-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
|
|
22
|
+
Documentation for this SDK is available at [folksrouter.io](https://folksrouter.io/docs/sdk/overview/).
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { FolksRouterClient, Network, SwapMode } from "@folks-router/js-sdk";
|
|
28
|
+
import { Algodv2, decodeUnsignedTransaction, generateAccount } from "algosdk";
|
|
29
|
+
|
|
30
|
+
const senderAccount = generateAccount();
|
|
31
|
+
const algodClient = new Algodv2("", "https://mainnet-api.algonode.cloud/", 443);
|
|
32
|
+
const folksRouterClient = new FolksRouterClient(Network.MAINNET);
|
|
33
|
+
|
|
34
|
+
async function main() {
|
|
35
|
+
// Fetch Swap Quote
|
|
36
|
+
const swapQuote = await folksRouterClient.fetchSwapQuote(0, 31566704, BigInt(10e6), SwapMode.FIXED_INPUT);
|
|
37
|
+
|
|
38
|
+
// Prepare Swap Transactions
|
|
39
|
+
const base64txns = await folksRouterClient.prepareSwapTransactions(senderAccount.addr, BigInt(10), swapQuote);
|
|
40
|
+
const unsignedTxns = base64txns.map((txn) => decodeUnsignedTransaction(Buffer.from(txn, "base64")));
|
|
41
|
+
const signedTxns = unsignedTxns.map((txn) => txn.signTxn(senderAccount.sk));
|
|
42
|
+
|
|
43
|
+
// Submit Transaction
|
|
44
|
+
await algodClient.sendRawTransaction(signedTxns).do();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main();
|
|
48
|
+
```
|