For Feria Nounish Artists: This documentation is inspired by Gabriel Lago from Cali, Colombia, who is building a Feria Nounish MiniApp for the artists participating in this year’s fair. The uploadToArweave function enables artists to upload their artwork and metadata to decentralized storage, creating permanent, onchain records of their contributions to the collective timeline.
Upload files to Arweave decentralized storage for use in your NFT collections and moments. This function works on client-side environments using the @ardrive/turbo-sdk web bundle.
This guide targets Next.js 16. The examples use the App Router and rely on Next.js 16’s native
Buffer support in browser bundles.Note: This function uploads files to Arweave and returns a URI that can be used in collection creation or moment creation.
Installation
Install the Turbo SDK and the Node.js polyfills required for browser environments:Next.js Configuration
The Turbo SDK uses Node.js built-ins (buffer, crypto, stream) that are not available in the browser. Add the following to your next.config.js to polyfill them and to prevent the SDK from being bundled on the server:
Function Implementation
client.ts
Create a singleton Turbo client authenticated with your Arweave wallet key:patchFetch.ts
The Turbo web SDK passes aReadableStream as the fetch body, which browsers mark as “disturbed” after the first read. This helper intercepts those calls and converts the stream to a Blob so the body can be reused across SDK retries:
uploadFile.ts
Core upload logic using the Turbo client:uploadToArweave.ts
The main entry point that applies the fetch patch around the upload:Parameters
Return Value
Returns a Promise that resolves to a string containing the Arweave URI in the format:ar://{transaction_id}
Environment Setup
You’ll need to set up your Arweave wallet key as an environment variable:Usage Examples
Basic Upload
Upload with Progress Tracking
Upload JSON Metadata
Use theuploadJson helper to upload plain objects directly:
uploadJson helper is implemented as:
Upload for Moment Content
React Hook Example
File Types Supported
The function supports any file type that can be stored on Arweave:- Images: PNG, JPEG, GIF, SVG, WebP
- Documents: PDF, TXT, MD
- Data: JSON, CSV, XML
- Media: MP4, MP3, WebM
- Archives: ZIP, TAR
Best Practices
- File Size: Turbo uploads are paid with Credits (not AR tokens directly). Larger files consume more credits. Top up your Turbo Credits balance at https://turbo.ar.io/topup.
- Content-Type Tagging: The function automatically tags files with their MIME type and file name for proper handling.
- Progress Tracking: Always implement progress tracking for better user experience, especially for larger files.
- Error Handling: Wrap upload calls in try-catch blocks to handle network issues or insufficient Turbo Credits.
- Metadata Structure: When uploading JSON metadata, follow standard NFT metadata schemas for compatibility with marketplaces.
Integration with Collection Creation
After uploading your metadata to Arweave, use the returned URI in your collection creation:Error Handling
Common errors and solutions:- Insufficient Turbo Credits: Ensure your Arweave wallet has enough Turbo Credits for the upload. Top up at https://turbo.ar.io/topup
- Invalid wallet key: Verify your
NEXT_PUBLIC_ARWEAVE_KEYis correctly base64 encoded - ReadableStream error: The
patchFetchhelper handles browser stream compatibility automatically - File too large: Consider compressing or optimizing your files before upload
Next Steps
After uploading files to Arweave:- Create a collection using your uploaded metadata URI
- Create moments with your uploaded content
- Browse the timeline to see your contributions