Blok SDK Documentation

Build decentralized applications with blockchain-backed profiles, file storage, and social features. Full TypeScript support with seamless MetaMask integration.

Quick Start Guide
Get up and running with Blok SDK in 5 minutes

1. Install the SDK

npm install @dot-blok/sdk

2. Initialize & Connect Wallet

import { BlokClient } from '@dot-blok/sdk';

const blok = new BlokClient({
  apiKey: 'your-api-key'
});

// Connect wallet
const { address } = 
  await blok.connectWallet();

3. Create a Profile

const profile = await blok.profile.create({
  handle: 'myusername',
  displayName: 'My Name',
  bio: 'Hello world!',
  avatar: avatarFile
});
Get API Keys
Wallet

Easy MetaMask integration for wallet connections and transactions

Profiles

Create and manage on-chain user profiles with customizable metadata

File Storage

Upload files to IPFS with on-chain verification and metadata tracking

Social Posts

Create, update, and delete posts with IPFS + blockchain security

Wallet API
MetaMask wallet connection and management
connectWallet()

Connect to user's MetaMask wallet

disconnectWallet()

Disconnect the current wallet

👤
Profile API
Create and manage user profiles on-chain
profile.get(address?)

Fetch a user profile by wallet address

profile.create(data)

Create a new on-chain profile

profile.update(data)

Update an existing profile

Files API
Upload and manage files on IPFS with blockchain tracking
files.getMyFiles()

Retrieve all files uploaded by connected wallet

files.uploadFile(file)

Upload a file to IPFS and store metadata on-chain

files.deleteFile(fileId)

Mark a file as deleted on-chain

Social API
Create and manage decentralized social posts
social.getPosts()

Fetch all active posts

social.createPost(content, image?)

Create a new post with optional image

social.updatePost(id, content)

Update an existing post

social.deletePost(id)

Delete a post

Code Examples
Common integration patterns and use cases

Connect Wallet & Create ProfilePopular

// Connect wallet
const { address } = 
  await blok.connectWallet();

// Create profile
const profile = await blok.profile.create({
  handle: 'johndoe',
  displayName: 'John Doe',
  bio: 'Web3 developer',
  twitter: '@johndoe',
  github: 'johndoe'
});

if (profile.success) {
  console.log('Profile created!');
  console.log('TX:', profile.txHash);
}

Upload File to IPFS

// Upload file
const result = await blok.files.uploadFile(file);

console.log('File CID:', result.fileCid);
console.log('File URL:', result.fileUrl);
console.log('TX Hash:', result.txHash);

// Get all files
const myFiles = 
  await blok.files.getMyFiles();

myFiles.forEach(f => {
  console.log(f.name, f.size);
});

Create Social Post

// Create post with image
const result = 
  await blok.social.createPost(
    'Hello, Web3! 🚀',
    imageFile
  );

console.log('Post CID:', result.postCid);
console.log('TX Hash:', result.txHash);

// Fetch all posts
const posts = 
  await blok.social.getPosts();

Update Profile

// Update existing profile
const result = await blok.profile.update({
  displayName: 'John D.',
  bio: 'Updated bio',
  avatar: newAvatarFile,
  website: 'https://john.dev'
});

// Get current profile
const profile = 
  await blok.profile.get();

console.log(profile.displayName);
console.log(profile.avatar); // IPFS URL
Requirements
Before you start using Blok SDK
✓

MetaMask Wallet

Browser extension or compatible Web3 wallet

✓

API Key

Valid API key from Blok platform

✓

Wallet Funds

Sufficient balance for gas fees

✓

Internet Connection

Active connection for IPFS uploads

Error Handling
Best practices for handling SDK errors
import { BlokClient } from '@dot-blok/sdk';

const blok = new BlokClient({ apiKey: 'your-key' });

try {
  await blok.connectWallet();
  
  const profile = await blok.profile.create({
    handle: 'myhandle',
    displayName: 'My Name'
  });

  if (profile.success) {
    console.log('Success!', profile.txHash);
  }
} catch (error) {
  console.error('Operation failed:', error.message);
  // Handle specific error cases
}
Additional Resources
Learn more and get support

📦 NPM Package

View package details and versions

View on NPM

🐙 GitHub Repository

Source code, issues, and contributions

View GitHub

💬 Support

Get help and report issues

Get Support

TypeScript Support: The SDK is written in TypeScript and includes full type definitions out of the box for excellent IDE support and type safety.