@rareprotocol/rare-cli 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -191,6 +191,82 @@ rare status --contract 0x...
191
191
  rare status --contract 0x... --token-id 1
192
192
  ```
193
193
 
194
+ ## SDK Client Usage
195
+
196
+ Use the client export when integrating RARE flows directly in your app code.
197
+
198
+ ```bash
199
+ npm install @rareprotocol/rare-cli viem
200
+ ```
201
+
202
+ ### Create a client
203
+
204
+ ```ts
205
+ import { createPublicClient, createWalletClient, http } from 'viem';
206
+ import { privateKeyToAccount } from 'viem/accounts';
207
+ import { sepolia } from 'viem/chains';
208
+ import { createRareClient } from '@rareprotocol/rare-cli/client';
209
+
210
+ const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
211
+ const publicClient = createPublicClient({
212
+ chain: sepolia,
213
+ transport: http(process.env.RPC_URL),
214
+ });
215
+
216
+ const walletClient = createWalletClient({
217
+ account,
218
+ chain: sepolia,
219
+ transport: http(process.env.RPC_URL),
220
+ });
221
+
222
+ const rare = createRareClient({ publicClient, walletClient });
223
+ ```
224
+
225
+ ### Search
226
+
227
+ `search.nfts` auto-applies the client chain unless you pass `chainIds`.
228
+
229
+ ```ts
230
+ const nfts = await rare.search.nfts({ query: 'portrait', take: 10 });
231
+ const collections = await rare.search.collections({ ownerAddresses: [account.address] });
232
+ ```
233
+
234
+ ### Upload media and mint
235
+
236
+ `media.upload` accepts a `Uint8Array` (Node `Buffer` works directly).
237
+
238
+ ```ts
239
+ import { readFile } from 'node:fs/promises';
240
+
241
+ const imageBytes = await readFile('./art.png');
242
+ const image = await rare.media.upload(imageBytes, 'art.png');
243
+
244
+ const tokenUri = await rare.media.pinMetadata({
245
+ name: 'My NFT',
246
+ description: 'Minted with the SDK client',
247
+ image,
248
+ tags: ['art'],
249
+ });
250
+
251
+ const minted = await rare.mint.mintTo({
252
+ contract: '0xYourContractAddress',
253
+ tokenUri,
254
+ to: '0xRecipientAddress',
255
+ });
256
+
257
+ console.log(minted.tokenId);
258
+ ```
259
+
260
+ ### Import an ERC-721 collection
261
+
262
+ `import.erc721` derives `chainId` from the client. If `owner` is omitted, it defaults to the configured account.
263
+
264
+ ```ts
265
+ await rare.import.erc721({
266
+ contract: '0xYourContractAddress',
267
+ });
268
+ ```
269
+
194
270
  ## Configuration
195
271
 
196
272
  Config is stored at `~/.rare/config.json`. Each chain has its own private key and RPC URL.