Skip to content

Quick Start

Install

npm
npm install @offchain-wtf/sdk

Get Content

import { OffchainClient } from '@offchain-wtf/sdk';
 
const client = new OffchainClient({
  gatewayUrl: 'https://gateway.example.com',
  privateKey: process.env.PRIVATE_KEY,
});
 
const content = await client.get('bafkreigyc3t7nakfpzdp4gb2hhmx5whfhnqp6qmzq2fm36aqyfmnmtq7ya');
console.log(content.data);

Payment and signing happen automatically. Each request costs $0.01 USDC.

Keep your private key on your backend server only.

Cache It (Optional)

const cache = new Map();
 
async function getCached(cid) {
  if (cache.has(cid)) return cache.get(cid);
  const content = await client.get(cid);
  cache.set(cid, content);
  return content;
}

That's it. Read the docs for more.