-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2801 from build-5/example/nft_purchase
added NFT purchase example
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |