Skip to main content

Purchase NFT

To purchase an NFT, you must call purchase on dataset(Dataset.NFT). purchase takes an object of type NftPurchaseTangleRequest as parameter.

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

purchase returns an oject of type OtrRequest<NftPurchaseTangleRequest>.

OTR Request Deep Link

The SDK provides the helper functions getFireflyDeepLink() and getBloomDeepLink() to generate deep links for OTR requests.

If you want to track the purchase you can use the track how-to.

Full How-To Code

import { Dataset } from '@build-5/interfaces';
import { Build5, SoonaverseOtrAddress, https, otr, SoonaverseApiKey } from '@build-5/sdk';

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

const origin = Build5.TEST;
// @ts-ignore
const otrAddress = SoonaverseOtrAddress[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());