Skip to content

Commit

Permalink
Merge pull request #2801 from build-5/example/nft_purchase
Browse files Browse the repository at this point in the history
added NFT purchase example
  • Loading branch information
adamunchained authored Feb 12, 2024
2 parents 799ffe9 + 7045b1e commit 5887627
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
27 changes: 27 additions & 0 deletions docs/docs/how-to/nft/purchase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Purchase NFT
tags:
- how-to
- purchase
- nft
- otr
---

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

<Tabs>
<TabItem value="otr" label="OTR">
To purchase NFT, you must call [`purchase`](../../reference-api/classes/NftOtrDataset.md#purchase) on `dataset(Dataset.NFT)`.
[`purchase`](../../reference-api/classes/NftOtrDataset.md#purchase) takes an object of type [`NftPurchaseTangleRequest`](../../reference-api/interfaces/NftPurchaseTangleRequest.md) as parameter.

```tsx file=../../../../packages/sdk/examples/nft/otr/purchase.ts#L4-L27
```

<DeepLink/>
</TabItem>
<TabItem value="https" label="HTTPS">
TODO
</TabItem>
</Tabs>
2 changes: 1 addition & 1 deletion docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const config = {
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl: '/',
onBrokenLinks: 'throw',
onBrokenAnchors: 'throw',
onBrokenAnchors: 'warn',
onBrokenMarkdownLinks: 'throw',
plugins: [
[
Expand Down
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const sidebars = {
{
'NFT API': [
'how-to/nft/create-collection',
'how-to/nft/purchase',
'how-to/nft/bulk-purchase',
'how-to/nft/create-metadata',
'how-to/nft/transfer',
Expand Down
30 changes: 30 additions & 0 deletions packages/sdk/examples/nft/otr/purchase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Dataset } from '@build-5/interfaces';
import { Build5, Build5OtrAddress, https, otr, SoonaverseApiKey } from '@build-5/sdk';

const collectionId = 'build5collectionid1';
const nftId = 'build5nftid1';

const origin = Build5.TEST;
// @ts-ignore
const otrAddress = Build5OtrAddress[origin];

async function main() {
const otrRequest = otr(otrAddress)
.dataset(Dataset.NFT)
.purchase({ collection: collectionId, nft: nftId });

const fireflyDeeplink = otrRequest.getFireflyDeepLink();
console.log('Firefly Deeplink: ', fireflyDeeplink);

console.log('\n');
console.log(
'Sending correct will cause NFT purchase and goes back to buyers wallet. Invalid amount will be refunded.',
);

const tag = otrRequest.getTag(fireflyDeeplink);
const obs = https(Build5.TEST).project(SoonaverseApiKey[Build5.TEST]).trackByTag(tag);
console.log('Listen to payment progress:');
obs.subscribe((n) => console.log('- update: ', n));
}

main().then(() => process.exit());

0 comments on commit 5887627

Please sign in to comment.