Code Examples
Explore integration examples and code samples for the Bloklab platform.
SDK Setup Examples
TypeScript
import { BloklabClient } from '@bloklab/sdk';
const client = new BloklabClient({
apiKey: process.env.BLOKLAB_API_KEY,
environment: 'production'
});
// Tokenize a real estate asset
const asset = await client.assets.create({
name: 'Downtown Office Building',
symbol: 'DOB',
assetType: 'real-estate',
valuation: 5000000,
location: 'New York, NY',
totalSupply: 1000000
});
Python
from bloklab import Client
client = Client(
api_key=os.getenv('BLOKLAB_API_KEY'),
environment='production'
)
# Create asset token
asset = client.assets.create({
'name': 'Premium Art Collection',
'type': 'collectible',
'valuation': 250000
})
Java
import io.bloklab.Client;
import io.bloklab.models.Asset;
Client client = new Client.Builder()
.apiKey(System.getenv("BLOKLAB_API_KEY"))
.environment("production")
.build();
Asset asset = client.assets().create(Asset.builder()
.name("Industrial Equipment")
.type("equipment")
.valuation(750000)
.build());
Integration Examples
Asset Management
Examples of creating and managing digital assets.
// Create a new asset
const asset = await client.assets.create({
name: 'Example Asset',
symbol: 'EXMPL',
type: 'security_token',
totalSupply: '1000000'
});
// Get asset details
const assetDetails = await client.assets.get(asset.id);
// Update asset
await client.assets.update(asset.id, {
metadata: {
description: 'Updated description'
}
});
Trading Operations
Examples of trading operations and order management.
// Place a market order
const order = await client.trading.createOrder({
assetId: 'asset_123',
side: 'buy',
type: 'market',
quantity: '100'
});
// Place a limit order
const limitOrder = await client.trading.createOrder({
assetId: 'asset_123',
side: 'sell',
type: 'limit',
quantity: '100',
price: '50.00'
});
// Get order status
const orderStatus = await client.trading.getOrder(order.id);
Market Data
Examples of accessing real-time market data.
// Subscribe to market data
client.market.subscribe(['asset_123'], (data) => {
console.log('Price:', data.price);
console.log('Volume:', data.volume);
});
// Get historical data
const history = await client.market.getHistory({
assetId: 'asset_123',
interval: '1h',
limit: 100
});
// Get order book
const orderBook = await client.market.getOrderBook('asset_123');
Webhook Integration
Examples of setting up and handling webhooks.
// Configure webhooks
await client.webhooks.configure({
url: 'https://your-domain.com/webhooks',
events: ['asset.created', 'order.completed'],
secret: 'your_webhook_secret'
});
// Verify webhook signature
const isValid = client.webhooks.verifySignature(
request.headers['x-webhook-signature'],
request.body
);
// Handle webhook events
app.post('/webhooks', (req, res) => {
const event = req.body;
switch(event.type) {
case 'asset.created':
handleAssetCreated(event.data);
break;
case 'order.completed':
handleOrderCompleted(event.data);
break;
}
res.status(200).send('OK');
});
Ready to Start Building?
Explore our comprehensive documentation and start integrating with Bloklab platform.