Skip to content

Commit

Permalink
Merge pull request #2796 from build-5/add/swap-how-to
Browse files Browse the repository at this point in the history
Add swap example
  • Loading branch information
adamunchained authored Feb 19, 2024
2 parents e0e3336 + a2bc019 commit 3457b0b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
48 changes: 48 additions & 0 deletions docs/docs/how-to/swap/create-swap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Create Swap
tags:
- how-to
- swap
- nft
- token
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import DeepLink from '../../_admonitions/_deep_link.md'

<Tabs>
<TabItem value="otr" label="OTR">
To create a swap order, you must call [`create`](../../reference-api/classes/SwapOtrDataset.md#create) on `dataset(Dataset.SWAP)`.
[`create`](../../reference-api/classes/SwapOtrDataset.md#create) takes an object of type [`SwapCreateTangleRequest`](../../reference-api/interfaces/SwapCreateTangleRequest.md) as parameter, in which you can specify the recipient, native tokens, NFTs and base token you are interested in.

```tsx file=../../../../packages/sdk/examples/swap/otr/create.ts#L21-L27
```

<DeepLink/>
</TabItem>
<TabItem value="https" label="HTTPS">
To create a swap order, you must call [`create`](../../reference-api/classes/SwapDataset.md#create) on `dataset(Dataset.SWAP)`.
[`create`](../../reference-api/classes/SwapDataset.md#create) takes an object of type [`SwapCreateRequest`](../../reference-api/interfaces/SwapCreateRequest.md) as parameter, in which you can specify the recipient, native tokens, NFTs and base token you are interested in.

```tsx file=../../../../packages/sdk/examples/swap/https/create.ts#L14-L29
```

afterwards you need to fund a specific address:

```tsx file=../../../../packages/sdk/examples/swap/https/create.ts#L31
```

and set the order as funded:

```tsx file=../../../../packages/sdk/examples/swap/https/create.ts#L35-L46
```

</TabItem>
</Tabs>

:::info setFunded

With `setFunded`, you can specify if you, as the bidder, are giving your final bid or keeping it open.

:::
5 changes: 5 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const sidebars = {
'how-to/nft/transfer',
],
},
{
'Swap': [
'how-to/swap/create-swap',
]
},
{
'Stamp API': [
'how-to/stamp/create-stamp',
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/examples/swap/https/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ async function main() {
},
});

console.log('Send bids to swap order address', response.payload.targetAddress);
const targetAddress = response.payload.targetAddress;
console.log('Send bids to swap order address', targetAddress);
console.log('Once bids are sent mark the swap as funded.');

await https(origin)
Expand Down

0 comments on commit 3457b0b

Please sign in to comment.