> For the complete documentation index, see [llms.txt](https://docs.chiliz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chiliz.com/pl/tworzenie/zaawansowane/praca-z-nft/mintowanie-z-rarible.md).

# Mintowanie z Rarible

Rarible to multichainowy protokół i marketplace NFT, który udostępnia SDK oraz API do budowania aplikacji NFT w wielu sieciach EVM.

Do mintowania NFT [Rarible Multichain SDK](https://docs.rarible.org/reference/getting-started) pozwala mintować do własnych lub współdzielonych kolekcji i natychmiast tworzyć zlecenia sprzedaży.

Ponieważ Rarible SDK nie obsługuje wysyłania plików do IPFS, nasze przykłady używają tutaj [Pinata](https://pinata.cloud/) jako hosta IPFS. Aby uzyskać klucz JWT, będziesz potrzebować konta Pinata.

Będą one również wymagać, abyś miał:

* Już wdrożony kontrakt ERC-721 na Chiliz Chain. Musisz samodzielnie wdrożyć [kontrakt OpenZeppelin ERC-721](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol) na Chiliz Chain. [Remix IDE](https://remix.ethereum.org/) daje ci IDE działające w przeglądarce, aby to zrobić. Nie zapomnij zweryfikować kontraktu za pomocą block explorera!
* Klucz API Rarible. Zobacz ich Getting Started, aby dowiedzieć się, jak go uzyskać:

{% embed url="<https://docs.rarible.org/docs/rarible-protocol>" %}

Aby korzystać z Rarible SDK, potrzebujemy kilku instalacji:

```bash
npm i @rarible/sdk @rarible/types ethers dotenv pinata
```

{% hint style="warning" %}
Zauważysz, że używamy `ethers`, który jest alternatywą dla `viem`, którego używaliśmy w innych sekcjach.\
Faktycznie [Rarible zaleca](https://docs.rarible.org/reference/getting-started#interacting-with-evm-wallets) deweloperom korzystanie z ethers.js lub web3.js do pracy z portfelami Web3 — a [web3.js](https://web3js.org/#/) [został wycofany w marcu 2025](https://blog.chainsafe.io/web3-js-sunset/), pozostawiając `ethers` jako de facto jedyny wybór.
{% endhint %}

## Mintowanie kolekcji NFT

Najpierw zbuduj swój plik .env:

```
# Chiliz RPC
RPC_URL=https://spicy-rpc.chiliz.com       # or a Mainnet RPC
PRIVATE_KEY=0xabc...                       # minter's key (server-side ONLY)

# Rarible
RARIBLE_API_KEY=your_rarible_api_key
COLLECTION_ADDRESS=0xYourCollectionOnChiliz
SUPPLY=1                                   # 1 = ERC-721, >1 = ERC-1155

# Pinata
PINATA_JWT=eyJhbGciOi...                   # Pinata JWT from dashboard
PINATA_GATEWAY=your-subdomain.mypinata.cloud

# Media / metadata inputs
IMAGE_PATH=./art/image.png
NAME=My Chiliz NFT
DESCRIPTION=Minted on-chain via Rarible SDK

```

Nasz preferowany workflow to:

1. Wyślij media do IPFS przez Pinata
2. Zbuduj i wyślij plik metadanych
3. Rarible SDK + mint on-chain

Oto pełny przykładowy skrypt, którym możesz się zainspirować:

{% code overflow="wrap" lineNumbers="true" fullWidth="true" %}

```bash
import 'dotenv/config'
import fs from 'fs'
import path from 'path'
import { Wallet, JsonRpcProvider } from 'ethers'
import { createRaribleSdk } from '@rarible/sdk'
import { toCollectionId, toUnionAddress } from '@rarible/types'
import { PinataSDK } from 'pinata'

function guessMime(p: string) {
  const ext = path.extname(p).toLowerCase()
  if (ext === '.png') return 'image/png'
  if (ext === '.jpg' || ext === '.jpeg') return 'image/jpeg'
  if (ext === '.webp') return 'image/webp'
  if (ext === '.gif') return 'image/gif'
  if (ext === '.mp4') return 'video/mp4'
  if (ext === '.webm') return 'video/webm'
  return 'application/octet-stream'
}

async function main() {
  // Upload media to IPFS
  const pinata = new PinataSDK({
    pinataJwt: process.env.PINATA_JWT!,
  })

  const mediaPath = process.env.IMAGE_PATH!
  const mediaBlob = new Blob([fs.readFileSync(mediaPath)], { type: guessMime(mediaPath) })
  const mediaFile = new File([mediaBlob], path.basename(mediaPath), { type: guessMime(mediaPath) })

  const mediaUpload = await pinata.upload.public.file(mediaFile)
  const imageUri = `ipfs://${mediaUpload.cid}`
  // console.log('imageUri:', imageUri)

  // Build & upload metadata file
  const metadata = {
    name: process.env.NAME!,
    description: process.env.DESCRIPTION!,
    image: imageUri,
    // animation_url: "ipfs://<cid>/video.mp4",
    // attributes: [{ trait_type: "Tier", value: "Gold" }],
  }
  const metaUpload = await pinata.upload.public.json(metadata)
  const metadataUri = `ipfs://${metaUpload.cid}`
  // console.log('metadataUri:', metadataUri)

  // Rarible on-chain mint
  const provider = new JsonRpcProvider(process.env.RPC_URL!)
  const wallet = new Wallet(process.env.PRIVATE_KEY!, provider)
  const sdk = createRaribleSdk(wallet, 'prod', { apiKey: process.env.RARIBLE_API_KEY! })

  // Union IDs use "<BLOCKCHAIN>:<address>" — here BLOCKCHAIN is "CHILIZ"
  const collectionId = toCollectionId(`CHILIZ:${process.env.COLLECTION_ADDRESS}`)
  const creator = toUnionAddress(`CHILIZ:${wallet.address}`)

  const { transaction, itemId } = await sdk.nft.mint({
    collectionId,
    uri: metadataUri,
    supply: Number(process.env.SUPPLY || 1), // 1 for 721, >1 for 1155
  })

  const { hash } = await transaction.wait()
  console.log('Minted item:', itemId, 'tx:', hash)
}

main().catch((e) => (console.error(e), process.exit(1)))

```

{% endcode %}

## Lazy-minting kolekcji NFT

Lazy Minting to opcja dla tych, którzy nie chcą ponosić kosztu mintowania NFT z góry, zanim wystawią je na sprzedaż. Mogą wystawić swoje NFT do zakupu, a następnie zmintować je dopiero wtedy, gdy zostanie kupione lub przetransferowane. Opłaty za gas są więc częścią procesu mintowania i są pokrywane przez kupującego.

Krótko mówiąc, lazy-minting oznacza umieszczenie NFT na blockchainie dopiero wtedy, gdy ktoś kupi NFT, a nie wcześniej.

Będziesz potrzebować poprawnie zdefiniowanego pliku .env:

```
# Chiliz RPC / wallet
RPC_URL=https://spicy-rpc.chiliz.com
PRIVATE_KEY=0xabc...                         # creator key (keep secret)

# Rarible
RARIBLE_API_KEY=your_rarible_api_key
COLLECTION_ADDRESS=0xYourCollectionOnChiliz   # ERC-721 or ERC-1155

# Pinata
PINATA_JWT=eyJhbGciOi...                      # Pinata JWT from dashboard
PINATA_GATEWAY=your-subdomain.mypinata.cloud  # optional (for previews)

# Media / metadata
IMAGE_PATH=./art/image.png
NAME=My Chiliz NFT
DESCRIPTION=Lazy-minted on Rarible (Chiliz)
SUPPLY=1                                      # 1 for 721; >1 for 1155 editions

```

A teraz przykładowy kod do lazy-mintingu twojego projektu:

{% code overflow="wrap" lineNumbers="true" fullWidth="true" %}

```typescript
import 'dotenv/config'
import fs from 'fs'
import path from 'path'
import { Wallet, JsonRpcProvider } from 'ethers'
import { createRaribleSdk } from '@rarible/sdk'
import { toCollectionId, toUnionAddress } from '@rarible/types'
import { PinataSDK } from 'pinata'

function guessMime(p: string) {
  const ext = path.extname(p).toLowerCase()
  if (ext === '.png') return 'image/png'
  if (ext === '.jpg' || ext === '.jpeg') return 'image/jpeg'
  if (ext === '.webp') return 'image/webp'
  if (ext === '.gif') return 'image/gif'
  if (ext === '.mp4') return 'video/mp4'
  if (ext === '.webm') return 'video/webm'
  return 'application/octet-stream'
}

async function main() {
  // Upload media to IPFS
  const pinata = new PinataSDK({
    pinataJwt: process.env.PINATA_JWT!,
  })

  const mediaPath = process.env.IMAGE_PATH!
  const mediaBlob = new Blob([fs.readFileSync(mediaPath)], { type: guessMime(mediaPath) })
  const mediaFile = new File([mediaBlob], path.basename(mediaPath), { type: guessMime(mediaPath) })
  const mediaUp = await pinata.upload.public.file(mediaFile)
  const imageUri = `ipfs://${mediaUp.cid}`

  const metadata = {
    name: process.env.NAME!,
    description: process.env.DESCRIPTION!,
    image: imageUri,
    // animation_url: "ipfs://<cid>/video.mp4",
    // attributes: [{ trait_type: "Tier", value: "Gold" }],
  }
  const metaUp = await pinata.upload.public.json(metadata)
  const metadataUri = `ipfs://${metaUp.cid}`

  // Rarible lazy mint
  const provider = new JsonRpcProvider(process.env.RPC_URL!)
  const wallet = new Wallet(process.env.PRIVATE_KEY!, provider)
  const sdk = createRaribleSdk(wallet, 'prod', { apiKey: process.env.RARIBLE_API_KEY! })
  const collectionId = toCollectionId(`CHILIZ:${process.env.COLLECTION_ADDRESS}`)
  const creator = toUnionAddress(`CHILIZ:${wallet.address}`)

  // Prepare & submit lazy mint (off-chain item; buyer mints on purchase)
  const prepared = await sdk.nft.mint.prepare({ collectionId })
  const result = await prepared.submit({
    uri: metadataUri,
    supply: Number(process.env.SUPPLY || 1),     // 1 for 721; >1 for 1155
    lazyMint: true,                              // Yes, make it lazy please
    creators: [{ account: creator, value: 10000 }], // 100% go to your wallet
    royalties: [],                               // e.g. [{ account: creator, value: 500 }] for 5%
  })

  // console.log('Lazy itemId:', result.itemId)
}

main().catch((e) => (console.error(e), process.exit(1)))

```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.chiliz.com/pl/tworzenie/zaawansowane/praca-z-nft/mintowanie-z-rarible.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
