A minimal TypeScript example that uses the RARE SDK client export:
import { createRareClient } from "@rareprotocol/rare-cli/client";It demonstrates:
- read operations (
search.nfts,search.collections) - optional write flow (
media.upload->media.pinMetadata->mint.mintTo)
- Node.js 22+
- An RPC URL for your target chain
- A funded wallet private key (use testnet first)
npm installCreate a .env file from the example:
cp .env.example .envRequired for all runs:
RPC_URLPRIVATE_KEYCHAIN(optional; defaults tosepolia)
Optional for mint flow:
MINT_EXAMPLE=trueCONTRACT_ADDRESSIMAGE_PATHRECIPIENT_ADDRESS(optional; defaults to your wallet address)
npm run exampleWhen MINT_EXAMPLE is not set to true, the script will:
- create a viem public + wallet client
- create a RARE client via
createRareClient - run
rare.search.nfts({ query: "portrait", take: 5 }) - run
rare.search.collections({ ownerAddresses: [yourAddress], take: 5 })
Set MINT_EXAMPLE=true and provide the mint env vars, then run:
npm run exampleThe script will then:
- read your local image file
- upload media to IPFS with
rare.media.upload - pin metadata with
rare.media.pinMetadata - mint with
rare.mint.mintTo
- Never commit
.envor private keys. - Use
sepolia/base-sepoliabefore mainnet. - Keep wallet permissions and funds minimal for testing.
src/simple-sdk-example.ts- the runnable SDK example.env.example- environment templateassets/- sample media files
This example uses the published @rareprotocol/rare-cli package version from package.json.