Skip to content

centrifuge/sdk

Repository files navigation

Codecov Build CI status

Latest Release

Centrifuge JavaScript SDK

CentrifugeSDK provides a JavaScript client to interact with the Centrifuge ecosystem. It provides a comprehensive interface to easily create and manage pools, nfts, loans and metadata.

Installation

CentrifugeSDK uses Viem under the hood. It's necessary to install it alongside the SDK.

npm install --save @centrifuge/sdk viem

Init and config

Create an instance and pass optional configuration

import Centrifuge from '@centrifuge/sdk'

const centrifuge = new Centrifuge()

The following config options can be passed on initilization of CentrifugeSDK:

  • environment: 'mainnet' | 'demo' | 'dev'
    • Optional
    • Default value: mainnet
  • rpcUrls: Record<number, string>
    • Optional
    • A object mapping chain ids to RPC URLs

Queries

Queries return Promise-like Observables. They can be either awaited to get a single value, or subscribed to to get fresh data whenever on-chain data changes.

try {
  const pool = await centrifuge.pools()
} catch (error) {
  console.error(error)
}
const subscription = centrifuge.pools().subscribe(
  (pool) => console.log(pool),
  (error) => console.error(error)
)
subscription.unsubscribe()

The returned results are either immutable values, or entities that can be further queried.

Transactions

To perform transactions, you need to set a signer on the centrifuge instance.

centrifuge.setSigner(signer)

signer can be a EIP1193-compatible provider or a Viem LocalAccount

With this you can call transaction methods. Similar to queries they can be awaited to get their final result, or subscribed to get get status updates.

const pool = await centrifuge.pool('1')
try {
  const status = await pool.closeEpoch()
  console.log(status)
} catch (error) {
  console.error(error)
}
const pool = await centrifuge.pool('1')
const subscription = pool.closeEpoch().subscribe(
  (status) => console.log(pool),
  (error) => console.error(error),
  () => console.log('complete')
)

Developer Docs

Dev server

yarn dev

Build

yarn build

Test

yarn test
yarn test:single <path-to-file>
yarn test:simple:single <path-to-file> # without setup file, faster and without tenderly setup

PR Naming Convention for Semantic Versioning

PR naming convention is used to determine the semantic version bump of the package. It is enforced by a GitHub action in each pull request.

Version bumps:

  • major: breaking changes
  • minor: new features
  • patch: bug fixes
  • none: no version bump, no publish

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published