Bulk Purchase NFTs
- OTR
- HTTPS
To bulk purchase NFTs, you must call bulkPurchase on dataset(Dataset.NFT).
bulkPurchase takes an object of type NftPurchaseBulkTangleRequest as parameter.
const otrRequest = otr(otrAddress)
.dataset(Dataset.NFT)
.bulkPurchase({ orders: nftIds.map((nftId) => ({ collection: collectionId, nft: nftId })) });
bulkPurchase returns an oject of type OtrRequest<NftPurchaseBulkRequest>.
OTR Request Deep Link
The SDK provides the helper functions getFireflyDeepLink() and getBloomDeepLink() to generate deep links for OTR requests.
To bulk purchase NFTs, you must call bulkPurchase on dataset(Dataset.NFT).
bulkPurchase takes an object of type NftPurchaseBulkRequest as parameter.
const order = await https(origin)
.project(SoonaverseApiKey[origin])
.dataset(Dataset.NFT)
.bulkPurchase({
address: address.bech32,
signature: signature.signature,
publicKey: {
hex: signature.publicKey,
network: Network.RMS,
},
body: {
orders: nftIds.map((nftId) => ({ collection: collectionId, nft: nftId })),
},
});
bulkPurchase returns an oject of type Transaction.
Full How-To Code
- OTR
- HTTPS
import { Dataset } from '@build-5/interfaces';
import { Build5, SoonaverseOtrAddress, otr } from '@build-5/sdk';
const collectionId = 'build5nftcollectionid';
const nftIds = ['build5nftid1', 'build5nftid2'];
const origin = Build5.TEST;
// @ts-ignore
const otrAddress = SoonaverseOtrAddress[origin];
async function main() {
const otrRequest = otr(otrAddress)
.dataset(Dataset.NFT)
.bulkPurchase({ orders: nftIds.map((nftId) => ({ collection: collectionId, nft: nftId })) });
const fireflyDeeplink = otrRequest.getFireflyDeepLink();
console.log(fireflyDeeplink);
console.log('Sending whatever amount:');
console.log(
'In case you send a random amount your funds will be credited back' +
' The response metadata will contain the exact amount needed and target address',
);
console.log('\n');
console.log('Sending correct amount:');
console.log(
'In case you send the exact amount needed, your request will be processed and the NFTs will be purchased',
);
console.log('\nIn both cases, if an NFT can not be pruchased the amount will be credited back.');
}
main().then(() => process.exit());
import { Dataset, Network } from '@build-5/interfaces';
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk';
import { address } from '../../utils/secret';
import { walletSign } from '../../utils/utils';
const collectionId = 'build5nftcollectionid';
const nftIds = ['build5nftid1', 'build5nftid2'];
async function main() {
const origin = Build5.TEST;
const member = await https(origin).createMember({
address: address.bech32,
signature: '',
body: {
address: address.bech32,
},
});
try {
const signature = await walletSign(member.uid, address);
const order = await https(origin)
.project(SoonaverseApiKey[origin])
.dataset(Dataset.NFT)
.bulkPurchase({
address: address.bech32,
signature: signature.signature,
publicKey: {
hex: signature.publicKey,
network: Network.RMS,
},
body: {
orders: nftIds.map((nftId) => ({ collection: collectionId, nft: nftId })),
},
});
console.log(
'Sent: ',
order.payload.amount,
' to ',
order.payload.targetAddress,
', full order object: ',
order,
);
console.log('Once the order is funded, payload.nftOrders will be update.');
console.log('If price and nft is set, it means that that NFT was bough.');
console.log('Otherwise error will contain an error code and amount will be credited.');
} catch (e) {
console.log(e);
return;
}
}
main().then(() => process.exit());