IPFS Pinning
The SDK supports two IPFS paths:
| Path | Use for | Credential |
|---|---|---|
| Intuition pinning service | pinThing, createAtomFromThing, batchCreateAtomsFromThings | Intuition pin API key (pinApiKey) |
| Direct Pinata upload | uploadJsonToPinata, createAtomFromIpfsUpload | Pinata API JWT (pinataApiJWT) |
pinThing does not require a Pinata account, but it does require an Intuition pin API key. Keep API keys in a trusted server runtime and do not expose them in public browser environment variables.
Intuition Pin API Keyβ
Configure the SDK once before calling pinThing or any SDK helper that auto-pins Thing metadata:
import { configureSdk } from '@0xintuition/sdk';
configureSdk({
pinApiKey: process.env.INTUITION_PIN_API_KEY,
});
You can also pass the key per call:
const uri = await pinThing(thing, {
pinApiKey: process.env.INTUITION_PIN_API_KEY,
});
pinThingβ
Pin a Thing object to IPFS via the Intuition pinning service.
SDK helpers accept the Thing fields directly (name, description, image, url). Raw GraphQL mutation requests use the GraphQL thing input wrapper.
Function Signatureβ
function pinThing(
variables: PinThingMutationVariables,
options?: PinThingOptions,
): Promise<string>;
Basic Exampleβ
import { configureSdk, pinThing } from '@0xintuition/sdk';
configureSdk({
pinApiKey: process.env.INTUITION_PIN_API_KEY,
});
const uri = await pinThing({
url: 'https://example.com',
name: 'Example Project',
description: 'A great project',
image: 'https://example.com/logo.png',
});
console.log('Pinned to IPFS:', uri); // ipfs://bafkreib...
Pin Thing and Create Atomβ
Use createAtomFromThing when you want the SDK to pin the Thing metadata and create the atom in one flow:
import { configureSdk, createAtomFromThing } from '@0xintuition/sdk';
import { parseEther } from 'viem';
configureSdk({
pinApiKey: process.env.INTUITION_PIN_API_KEY,
});
const atom = await createAtomFromThing(
{ walletClient, publicClient, address },
{
url: 'https://myproject.com',
name: 'My Project',
description: 'A blockchain project',
image: 'https://myproject.com/logo.png',
},
{ depositAmount: parseEther('0.05') },
);
console.log('Atom created:', atom.state.termId);
console.log('IPFS URI:', atom.uri);
Direct Pinata Uploadsβ
Use direct Pinata uploads when you want to bring your own Pinata account. These paths do not use the Intuition pin API key.
uploadJsonToPinataβ
Upload JSON directly to Pinata.
Function Signatureβ
function uploadJsonToPinata(
pinataApiJWT: string,
data: object,
): Promise<PinataUploadResult>;
Basic Exampleβ
import { uploadJsonToPinata } from '@0xintuition/sdk';
const result = await uploadJsonToPinata(process.env.PINATA_API_JWT!, {
name: 'My Data',
description: 'Some metadata',
properties: {
key: 'value',
},
});
console.log('IPFS Hash:', result.IpfsHash);
console.log('Size:', result.PinSize, 'bytes');
console.log('URI:', `ipfs://${result.IpfsHash}`);
Return Typeβ
type PinataUploadResult = {
IpfsHash: string;
PinSize: number;
Timestamp: string;
};
Getting a Pinata API Keyβ
Direct Pinata upload paths require a Pinata API JWT:
- Sign up at pinata.cloud
- Go to API Keys
- Create a new API key
- Copy the JWT token
- Store it securely in environment variables
PINATA_API_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Batch Pin Multiple Itemsβ
import { configureSdk, pinThing } from '@0xintuition/sdk';
configureSdk({
pinApiKey: process.env.INTUITION_PIN_API_KEY,
});
async function batchPin(things: any[]) {
return Promise.all(things.map((thing) => pinThing(thing)));
}
const projects = [
{
name: 'Project A',
description: 'Project A metadata',
image: 'https://a.com/logo.png',
url: 'https://a.com',
},
{
name: 'Project B',
description: 'Project B metadata',
image: 'https://b.com/logo.png',
url: 'https://b.com',
},
];
const ipfsUris = await batchPin(projects);
console.log('Pinned', ipfsUris.length, 'items to IPFS');
Error Handlingβ
import { pinThing } from '@0xintuition/sdk';
async function safePinThing(thing: any) {
try {
const uri = await pinThing(thing);
return { success: true, uri };
} catch (error) {
console.error('Failed to pin:', error);
return { success: false, error: error.message };
}
}
Common causes include a missing pinApiKey, an invalid API key, missing metadata fields, or image URLs that cannot be fetched by the pinning service.
Related Functionsβ
- createAtomFromThing - Create atom with auto-pinning
- createAtomFromIpfsUri - Create from IPFS URI
- createAtomFromIpfsUpload - Upload directly to Pinata and create