Skip to content

Commit

Permalink
Merge pull request rarible#399 from VitalyLyaper/feature/add-buy-func…
Browse files Browse the repository at this point in the history
…tion-descr

"type: docs"
  • Loading branch information
VitalyLyaper authored Nov 18, 2022
2 parents 229e07f + 4c29ea0 commit 5c7fa15
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions docs/reference/buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Buy NFT with Rarible Protocol
description: How to buy NFT using Rarible Multichain Protocol
---

# Prerequisites

To buy NFT with Rarible Protocol you should have order id for NFT you are interested in - you can get order id with [Rarible API](search-capabilities.md)

You can buy NFTs with Rarible Multichain Protocol on different blockchains.

--8<-- "docs/snippets/preparation-sdk.md"

# Buy an NFT

You can buy any NFTfor which sell order is created

Use `buy` function:

```typescript
import { createRaribleSdk } from "@rarible/sdk"
import { toOrderId} from "@rarible/types"

async function buyNft(orderId: string) {
const sdk = createRaribleSdk(wallet, "dev")

// Get order info
const buy = await sdk.order.buy.prepare({
orderId: toOrderId(orderId)
})

/**
* Number of NFTs to buy or to sell (in case of accepting bids)
* amount: number
* Origin fees, if not supported by the underlying contract, will throw Error
* originFees?: UnionPart[]
* Payouts, if not supported by the underlying contract, will throw Error
* payouts?: UnionPart[]
* Use infinite approvals (for ERC-20)
* infiniteApproval?: boolean
* ItemId for fill collection order
* itemId?: ItemId | ItemId[]
* Max fees value. Should be greater than 0. If required and not provided, will throw Error
* maxFeesBasePoint?: number,
* Force pay royalties. It's working only on AMM orders
* addRoyalties?: boolean
*/

// Send transaction
const result = await buy.submit(
amount: 1, //amount of NFTs you want to buy
)
// result: IBlockchainTransaction
}
```

* `orderId` — Id of NFT sale order, has format `${blockchain}:${orderId}`. For example, `ETHEREUM:0x19f487016770542dc6137b06499a4f7b42c9580f12d85d6347964b03b7682143`
* `amount` — amount of NFT tokens you want to buy

See more information about usage Protocol SDK on [https://github.com/rarible/sdk](https://github.com/rarible/sdk)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ nav:
- "Mint": "reference/mint.md"
- "Sell Order": "reference/order.md"
- "Mint and Sell": "reference/mint-and-sell.md"
- "Buy NFT": "reference/buy.md"
- "Create and Accept Bid": "reference/bid.md"
- "Transfer": "reference/transfer.md"
- "Burn": "reference/burn.md"
Expand Down

0 comments on commit 5c7fa15

Please sign in to comment.