New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@chainsafe/open-creator-rails-sdk

Package Overview
Dependencies
Maintainers
4
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/open-creator-rails-sdk

TypeScript SDK for interacting with Open Creator Rails contracts and indexer.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
4
Created
Source

Open Creator Rails SDK

TypeScript SDK for interacting with Open Creator Rails

Install

Published on npm as @chainsafe/open-creator-rails-sdk.

pnpm add @chainsafe/open-creator-rails-sdk viem
# npm install @chainsafe/open-creator-rails-sdk viem

Quick start

import { createPublicClient, createWalletClient, http } from "viem";
import { sepolia } from "viem/chains";
import { OcrSdk } from "@chainsafe/open-creator-rails-sdk";

const publicClient = createPublicClient({
  chain: sepolia,
  transport: http(process.env.RPC_URL!),
});

const walletClient = createWalletClient({
  chain: sepolia,
  transport: http(process.env.RPC_URL!),
  account: /* your account */,
});

const sdk = new OcrSdk({
  publicClient,
  walletClient,
  registryAddress,
  indexerUrl: process.env.INDEXER_URL, // optional
});

API overview

The SDK exposes:

  • Namespaced contract APIs
    • sdk.AssetRegistry.* wraps AssetRegistry contract methods
    • sdk.Asset.* wraps Asset contract methods
  • Bound "Asset client" helper
    • sdk.getAsset({ assetAddress }) and sdk.getAssetById({ assetId }) return an object that remembers assetAddress.
  • Indexer namespace
    • sdk.indexer.* exposes indexer-only queries that are not possible with simple onchain reads.

Namespaced contract usage

// AssetRegistry reads
const assetAddress = await sdk.AssetRegistry.getAsset({ assetId });
const exists = await sdk.AssetRegistry.viewAsset({ assetId });

// Asset reads (namespace form)
const owner = await sdk.Asset.owner({ assetAddress });
const token = await sdk.Asset.getTokenAddress({ assetAddress });

// Asset reads (bound client form)
const asset = sdk.getAsset({ assetAddress }); // or: await sdk.getAssetById({ assetId })
await asset.setSubscriptionPrice({ newSubscriptionPrice: 123n });

Write methods (require walletClient)

All write methods require walletClient in the SDK config and walletClient.account to be set.

await sdk.AssetRegistry.updateCreatorFeeShare({ creatorFeeShare: 60n });
await sdk.Asset.setSubscriptionPrice({ assetAddress, newSubscriptionPrice: 123n });

// Or with the bound asset client:
await asset.setSubscriptionPrice({ newSubscriptionPrice: 123n });

Indexer support

If you pass indexerUrl, the SDK exposes a dedicated indexer namespace at sdk.indexer.

Indexer namespace (sdk.indexer)

if (!sdk.indexer) throw new Error("indexerUrl not configured");

// Subscription for a specific asset + user
const sub = await sdk.indexer.getSubscription({ assetAddress, user });

// All subscriptions for a user (across assets), optionally only active ones
const activeSubs = await sdk.indexer.listSubscriptionsByUser({ user, activeOnly: true });

// Asset metadata (indexed)
const assetEntity = await sdk.indexer.getAsset({ assetAddress });

// Assets indexed for a registry
const assetsInRegistry = await sdk.indexer.listAssetsByRegistry({ registryAddress });

Source selection

Some methods accept source?: "auto" | "onchain" | "indexer":

  • "auto" (default): try indexer (if configured), then fall back to onchain
  • "onchain": only onchain reads
  • "indexer": only indexer; throws if the indexer request fails

Indexer-backed reads

These methods are implemented with indexer-first + fallback behavior:

// Subscription status by assetId + user
const status = await sdk.getSubscriptionStatus({ assetId, user, source: "auto" });

// Subscription status by assetAddress + user
const status2 = await sdk.Asset.getSubscriptionStatus({ assetAddress, user, source: "auto" });

// Asset owner by assetAddress
const owner2 = await sdk.Asset.getOwner({ assetAddress, source: "auto" });

Local Node (Anvil) + SDK Testing

This SDK can be tested end-to-end against a local Anvil chain using the contracts from the open-creator-rails submodule.

Prerequisites

  • Install Foundry (provides anvil + forge).
  • Initialize the contracts submodule:
npm run submodule:pull

These tests start Anvil, deploy TestToken and AssetRegistry, run subscribe/getSubscriptionStatus, advance time, and then run claimCreatorFee.

npm run test:integration

Manual debugging (optional)

Start Anvil on the default port:

anvil --chain-id 31337 --port 8545

Then point your SDK clients at it (as shown in the Usage section above) by setting:

export RPC_URL=http://127.0.0.1:8545

Maintenance

Updating git submodules

This repo includes the open-creator-rails submodule (contracts + deployment JSON). When upstream main changes, update the submodule and commit the new submodule SHA value (gitlink) in this repo.

  • Pull the latest submodule commits:
npm run submodule:pull
  • Commit the updated gitlink SHAs in this repository:
git status
git add open-creator-rails
git commit -m "chore: update submodules"

Publishing to npm

Package: @chainsafe/open-creator-rails-sdk (public, ChainSafe org).

pnpm install
pnpm run build
pnpm run test
pnpm run lint
npm version patch   # or minor / major
git push && git push --tags
npm publish --access public

Requires npm login as a user with publish access to the @chainsafe scope. prepack builds dist/ automatically before pack/publish.

FAQs

Package last updated on 03 Jun 2026

Related posts