-
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 #2800 from build-5/examples/auction
Auction examples
- Loading branch information
Showing
4 changed files
with
144 additions
and
0 deletions.
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,31 @@ | ||
--- | ||
title: Create Auction | ||
tags: | ||
- how-to | ||
- auction | ||
--- | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import DeepLink from '../../_admonitions/_deep_link.md' | ||
|
||
Auction APIs allows you to run generic auction without or with an asset. Asset can be NFT. | ||
|
||
<Tabs> | ||
<TabItem value="otr" label="OTR"> | ||
To create auction, you must call [`AuctionOtrDataset`](../../reference-api/classes/AuctionOtrDataset.md#create) on `dataset(Dataset.AUCTION)`. | ||
[`create`](../../reference-api/classes/AuctionOtrDataset.md#create) takes an object of type [`AuctionCreateTangleRequest`](../../reference-api/interfaces/AuctionCreateTangleRequest.md) as parameter. | ||
|
||
```tsx file=../../../../packages/sdk/examples/auction/otr/create.ts#L4-L47 | ||
``` | ||
|
||
<DeepLink/> | ||
</TabItem> | ||
<TabItem value="https" label="HTTPS"> | ||
To create auction, you must call [`create`](../../reference-api/classes/AuctionDataset.md#create) on `dataset(Dataset.AUCTION)`. | ||
[`create`](../../reference-api/classes/NftDataset.md#create) takes an object of type [`AuctionCreateRequest`](../../reference-api/interfaces/AuctionCreateRequest.md) as parameter. | ||
|
||
```tsx file=../../../../packages/sdk/examples/auction/https/create.ts#L6-L63 | ||
``` | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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'; | ||
|
||
async function main() { | ||
const origin = Build5.TEST; | ||
const userSign = await walletSign(address.bech32, address); | ||
|
||
try { | ||
// To create a generic auction we send an https request with the needed params | ||
let auction = await https(origin) | ||
.project(SoonaverseApiKey[origin]) | ||
.dataset(Dataset.AUCTION) | ||
.create({ | ||
address: address.bech32, | ||
signature: userSign.signature, | ||
publicKey: { | ||
hex: userSign.publicKey, | ||
network: Network.RMS, | ||
}, | ||
body: { | ||
auctionFloorPrice: 1000000, | ||
auctionFrom: new Date(), | ||
auctionLength: 8.64e7, // 1 day in milliseconds | ||
maxBids: 1, | ||
minimalBidIncrement: 1000000, | ||
network: Network.RMS, | ||
space: 'build5spaceid', | ||
}, | ||
}); | ||
|
||
// Once auction is created we can bid on it using the https request | ||
// The response will be a transaction object. | ||
// Use the targetAddress on this transaction object to send funds and bid on the auction | ||
const transction = await https(origin) | ||
.project(SoonaverseApiKey[origin]) | ||
.dataset(Dataset.AUCTION) | ||
.bid({ | ||
address: address.bech32, | ||
signature: userSign.signature, | ||
publicKey: { | ||
hex: userSign.publicKey, | ||
network: Network.RMS, | ||
}, | ||
body: { auction: auction.uid }, | ||
}); | ||
console.log('Target address ', transction.payload.targetAddress); | ||
|
||
// Once auction is no longer active we can re fetch it to see the winning bid and bidder | ||
auction = await https(origin) | ||
.project(SoonaverseApiKey[origin]) | ||
.dataset(Dataset.AUCTION) | ||
.id(auction.uid) | ||
.get(); | ||
console.log('Highest bid ', auction.auctionHighestBid); | ||
console.log('Highest bidder ', auction.auctionHighestBidder); | ||
} catch (error) { | ||
console.error('Error: ', error); | ||
} | ||
} | ||
|
||
main().then(() => process.exit()); |
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,47 @@ | ||
import { Dataset, Network } from '@build-5/interfaces'; | ||
import { Build5, Build5OtrAddress, SoonaverseApiKey, https, otr } from '@build-5/sdk'; | ||
|
||
async function main() { | ||
const origin = Build5.TEST; | ||
// @ts-ignore | ||
const otrAddress = Build5OtrAddress[origin]; | ||
|
||
try { | ||
// To create a generic auction we send an otr request with the needed params | ||
const otrCreateRequest = otr(otrAddress).dataset(Dataset.AUCTION).create({ | ||
auctionFloorPrice: 1000000, | ||
auctionFrom: new Date(), | ||
auctionLength: 8.64e7, // 1 day in milliseconds | ||
maxBids: 1, | ||
minimalBidIncrement: 1000000, | ||
network: Network.RMS, | ||
space: 'build5spaceid', | ||
}); | ||
|
||
const fireflyDeeplink = otrCreateRequest.getFireflyDeepLink(); | ||
console.log(fireflyDeeplink); | ||
|
||
// Once the request is sent the auction will be created and the funds will be credited back | ||
// The response output's metadata will contain an auction filed with the auction uid. | ||
// We can use this id to bid on the auction | ||
const auctionUid = 'auction id retrieved from tangle'; | ||
const otrBidRequest = otr(otrAddress).dataset(Dataset.AUCTION).bid({ | ||
auction: auctionUid, | ||
}); | ||
// Use this deepling to send funds and bid on the auction | ||
console.log(otrBidRequest.getFireflyDeepLink()); | ||
|
||
// Once auction is no longer active we can fetch it to see the winning bid and bidder | ||
const auction = await https(origin) | ||
.project(SoonaverseApiKey[origin]) | ||
.dataset(Dataset.AUCTION) | ||
.id(auctionUid) | ||
.get(); | ||
console.log('Highest bid ', auction.auctionHighestBid); | ||
console.log('Highest bidder ', auction.auctionHighestBidder); | ||
} catch (error) { | ||
console.error('Error: ', error); | ||
} | ||
} | ||
|
||
main().then(() => process.exit()); |