Turbo SDK
The Turbo SDK provides a high-level interface for uploading data to Arweave through Turbo's optimized infrastructure. Built with TypeScript, it offers seamless integration with built-in error handling, automatic retries, and transparent pricing.
Quick Start
Install the SDK
npm install @ardrive/turbo-sdk
Use the SDK
import { TurboFactory, USD } from '@ardrive/turbo-sdk';
import fs from 'fs';
// Create an authenticated client
const turbo = TurboFactory.authenticated({ privateKey: yourPrivateKey });
// Upload data with automatic payment
const result = await turbo.uploadFile({
fileStreamFactory: () => fs.createReadStream('./my-file.pdf'),
fileSizeFactory: () => fs.statSync('./my-file.pdf').size,
});
console.log('Upload successful:', result);
Install the SDK
npm install @ardrive/turbo-sdk
Install polyfills (required for web environments)
Polyfills are required for React web environments due to the use of crypto
, buffer
and process
types in the SDK's dependencies.
npm install --save-dev vite-plugin-node-polyfills
// vite.config.js
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
export default defineConfig({
plugins: [
nodePolyfills({
globals: {
Buffer: true,
global: true,
process: true,
},
}),
],
});
Configure your bundler (Webpack, Vite, Rollup, etc.) to provide polyfills for crypto
, process
, and buffer
. Refer to your bundler's documentation for polyfill configuration.
Use the SDK
import { TurboFactory, USD } from '@ardrive/turbo-sdk';
// Create an authenticated client
const turbo = TurboFactory.authenticated({ privateKey: yourPrivateKey });
// Upload data with automatic payment
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const result = await turbo.uploadFile({
fileStreamFactory: () => file.stream(),
fileSizeFactory: () => file.size,
});
console.log('Upload successful:', result);
<!DOCTYPE html>
<html>
<head>
<title>Turbo SDK Upload Example</title>
<script type="module">
// Polyfills are included in the minimized web bundle, so not necessary to import directly
import { TurboFactory } from 'https://unpkg.com/@ardrive/turbo-sdk@latest';
// Function to handle file upload
async function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const privateKeyInput = document.getElementById('privateKey');
if (!file) {
alert('Please select a file');
return;
}
if (!privateKeyInput.value) {
alert('Please enter your private key');
return;
}
try {
// Show loading state
document.getElementById('status').textContent = 'Uploading...';
// Create authenticated client
const turbo = TurboFactory.authenticated({
privateKey: privateKeyInput.value
});
// Upload file
const result = await turbo.uploadFile({
fileStreamFactory: () => file.stream(),
fileSizeFactory: () => file.size,
});
// Show success
document.getElementById('status').innerHTML = `
<p style="color: green;">Upload successful!</p>
<p>Transaction ID: ${result.id}</p>
<p>Data Item ID: ${result.dataItemId}</p>
`;
} catch (error) {
document.getElementById('status').innerHTML = `
<p style="color: red;">Error: ${error.message}</p>
`;
}
}
// Add click handler
window.addEventListener('load', () => {
document.getElementById('uploadBtn').addEventListener('click', uploadFile);
});
</script>
</head>
<body>
<h1>Turbo SDK Upload Example</h1>
<div>
<label>
Private Key (JWK):
<input type="password" id="privateKey" style="width: 300px;" />
</label>
</div>
<div style="margin-top: 10px;">
<label>
Select File:
<input type="file" id="fileInput" />
</label>
</div>
<button id="uploadBtn" style="margin-top: 10px;">Upload to Arweave</button>
<div id="status" style="margin-top: 20px;"></div>
</body>
</html>
API Reference & Documentation
API Reference
Complete API documentation for all Turbo client methods
SDK Details
Advanced features, events, logging, and credit sharing
Core Features
Upload Management
Authenticated and unauthenticated upload clients with retry logic
Events & Monitoring
Monitor upload progress and handle events in real-time
Credit Sharing
Manage shared credit pools for streamlined billing
Logging & Configuration
Configure logging for debugging and monitoring uploads
How is this guide?