Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added NFT purchase example #2801

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -57,6 +57,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());