Blok SDK Documentation
Build decentralized applications with blockchain-backed profiles, file storage, and social features. Full TypeScript support with seamless MetaMask integration.
1. Install the SDK
npm install @dot-blok/sdk2. 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
});Easy MetaMask integration for wallet connections and transactions
Create and manage on-chain user profiles with customizable metadata
Upload files to IPFS with on-chain verification and metadata tracking
Create, update, and delete posts with IPFS + blockchain security
connectWallet()Connect to user's MetaMask wallet
disconnectWallet()Disconnect the current wallet
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.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.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
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 URLMetaMask 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
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
}TypeScript Support: The SDK is written in TypeScript and includes full type definitions out of the box for excellent IDE support and type safety.