@cere-ddc-sdk/ddc-client
v3.1.0
Published
DDC client
Keywords
Readme
@cere-ddc-sdk/ddc-client
The DDC Client package provides easy-to-use wrapper around low-level APIs calls that flow from an application to a DDC infrastructure. It handles all required blockchain operations as well as provides concise API to store and read objects.
Installation
Using NPM:
npm install @cere-ddc-sdk/ddc-client --saveUsing yarn:
yarn add @cere-ddc-sdk/ddc-clientUsage
A quick guide of how to upload a file to DDC Testnet using the DdcClient API.
@cere-ddc-sdk/ddc-client3.0 is ESM-only and requires Node ≥ 22.11. Upgrading from 2.x? See MIGRATION.md — the network presets (TESTNET/DEVNET/MAINNET) are gone, replaced by explicitblockchain/clusterId/storageUrlconfig.
Create a
DdcClientinstanceimport * as fs from 'fs'; import { DdcClient, File, FileUri } from '@cere-ddc-sdk/ddc-client'; const seed = 'hybrid label reunion only dawn maze asset draft cousin height flock nation'; const clusterId = '0x...'; const ddcClient = await DdcClient.create(seed, { blockchain: 'testnet', clusterId, storageUrl: 'https://storage.testnet.cere.network', });blockchainaccepts a network name ('mainnet' | 'testnet' | 'devnet'), a websocket RPC URL, or an already-connectedCereClient. AddcdnUrlto read through a separate endpoint; reads fall back tostorageUrlwithout it.The account used to create the instance should have positive balance and DDC deposit
Create a new public bucket
const bucketId = await ddcClient.createBucket({ isPublic: true });The bucket is created in the cluster from
config.clusterId—createBucketno longer takes a cluster argument.Upload a file to DDC
const filePath = './my-picture.jpg'; const fileStats = fs.statSync(filePath); const fileStream = fs.createReadStream(filePath); const file = new File(fileStream, { size: fileStats.size }); const fileUri = await ddcClient.store(bucketId, file); console.log('The uploaded file CID', fileUri.cid)That is it. You can open the file from your browser:
const fileUrl = `https://storage.testnet.cere.network/${bucketId}/${fileUri.cid}`; console.log('The file URL', fileUrl);or download it using the SDK
const fileResponse = await ddcClient.read(fileUri); const content = await fileResponse.arrayBuffer(); console.log(content);Reconstruct the URI later with
new FileUri(bucketId, cid).
Documentation
For more information about what this package provides, see API reference
Examples
License
Licensed under the Apache License
