Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
362 changes: 362 additions & 0 deletions ARCHITECTURE_DIAGRAMS.md

Large diffs are not rendered by default.

352 changes: 352 additions & 0 deletions ARWEAVE_MIGRATION_SUMMARY.md

Large diffs are not rendered by default.

231 changes: 231 additions & 0 deletions ARWEAVE_QUICK_REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/// ============================================================================
/// ARWEAVE QUICK REFERENCE - 60 SECOND GUIDE
/// ============================================================================

/*

πŸ”— ARWEAVE vs IPFS - Quick Comparison
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Feature β”‚ IPFS β”‚ Arweave (NEW) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Data Guarantee β”‚ Dependent on pinners β”‚ 200+ years β”‚
β”‚ Cost Model β”‚ Recurring pinning β”‚ One-time payment β”‚
β”‚ Reference Type β”‚ Content hash β”‚ Transaction ID β”‚
β”‚ Hash Format β”‚ Qm... (46 chars) β”‚ 43 char string β”‚
β”‚ Storage Time β”‚ As long as pinned β”‚ Forever guaranteed β”‚
β”‚ Blockchain Ready β”‚ Sort of β”‚ Perfect fit β”‚
β”‚ Gateway Reliability β”‚ Variable β”‚ Designed for it β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

═══════════════════════════════════════════════════════════════════════════════

πŸ“š KEY FILES REFERENCE

β”Œβ”€ Service (Low-level API)
β”‚ lib/utils/services/arweave_services.dart
β”‚ └─ Functions: uploadToArweave(), verifyArweaveTransaction()
β”‚ └─ Model: ArweaveUploadResult
β”‚
β”œβ”€ Provider (State Management)
β”‚ lib/providers/arweave_provider.dart
β”‚ └─ Class: ArweaveProvider extends ChangeNotifier
β”‚ └─ Purpose: Cache TX IDs, manage upload state
β”‚
β”œβ”€ Data Models
β”‚ lib/models/media_file.dart
β”‚ └─ Classes: MediaFile, NFTMediaAsset
β”‚ └─ Purpose: Store media with provider type (IPFS vs Arweave)
β”‚
└─ Updated UI
lib/pages/mint_nft/mint_nft_images.dart
└─ Now uses Arweave instead of IPFS

═══════════════════════════════════════════════════════════════════════════════

⚑ MOST COMMON USAGE PATTERNS

1️⃣ UPLOAD SINGLE IMAGE:

final result = await uploadToArweave(
imageFile,
(isLoading) => setState(() { _loading = isLoading; }),
metadata: {'owner': userId},
);

if (result != null) {
print('TX ID: ${result.transactionId}');
print('URL: ${result.fileUrl}');
// Send result.transactionId to blockchain
}

2️⃣ UPLOAD MULTIPLE IMAGES:

final results = await uploadMultipleToArweave(
[file1, file2, file3],
(current, total) => print('$current/$total'),
);

final txIds = results
.whereType<ArweaveUploadResult>()
.map((r) => r.transactionId)
.toList();

3️⃣ USE PROVIDER FOR STATE:

final arweaveProvider =
Provider.of<ArweaveProvider>(context, listen: false);

final result = await arweaveProvider.uploadFileToArweave(
'my_file_id',
imageFile,
);

4️⃣ VERIFY BEFORE STORING ON-CHAIN:

final isValid = await verifyArweaveTransaction(txId);
if (isValid) {
await contract.submitData(txId);
}

═══════════════════════════════════════════════════════════════════════════════

🎯 IMPORTANT CONCEPTS

TX ID (Transaction ID):
β€’ Permanent reference to data
β€’ 43 character string
β€’ Can be stored in smart contracts
β€’ Enables Web3 data integrity
β€’ Example: "fCuK_sHFD72tM6x5XhDXXXXXXXXXXXXXX"

Gateway URL:
β€’ Full URL: "https://arweave.net/{txId}"
β€’ Use in Image.network() directly
β€’ Can fallback to other gateways

ArweaveUploadResult:
β€’ Returned from uploadToArweave()
β€’ Contains: transactionId, fileUrl, fileSize, uploadedAt
β€’ Has toJson() for persistence

Metadata:
β€’ Optional tags stored with transaction
β€’ Indexed by Arweave network
β€’ Useful for categorizing uploads
β€’ Example: {'owner': userId, 'type': 'nft'}

═══════════════════════════════════════════════════════════════════════════════

βœ… CHECKLIST: Using Arweave in a New Feature

β–‘ Import arweave_services and arweave_provider
β–‘ Call uploadToArweave() to upload files
β–‘ Capture the transactionId from result
β–‘ Use ArweaveProvider for loading state
β–‘ Create MediaFile model for persistence
β–‘ Send transactionId to blockchain
β–‘ Verify transaction before storing on-chain
β–‘ Display TX ID (optional) for transparency
β–‘ Cache TX ID in provider to avoid re-uploads
β–‘ Handle errors gracefully

═══════════════════════════════════════════════════════════════════════════════

πŸ” COMMON ERRORS & FIXES

ERROR: "No transaction ID in response"
FIX: Check Arweave gateway is accessible
Verify file format and size

ERROR: "Upload timeout"
FIX: Files >5MB may take 5+ minutes
Increase timeout or use Bundlr

ERROR: "Transaction not verified"
FIX: Wait a few seconds before verifying
Check gateway accessibility
Try alternative gateway

ERROR: "Image won't load"
FIX: Verify TX ID is correct
Check arweave.net gateway is up
Use alternative gateway URL

═══════════════════════════════════════════════════════════════════════════════

🌐 ARWEAVE GATEWAYS

Primary: https://arweave.net
Backup: https://ar-io.dev
Backup: https://gateway.irys.xyz

All serve the same data, can use any in Image.network()

═══════════════════════════════════════════════════════════════════════════════

πŸ’° COST ESTIMATE

File Size β”‚ Arweave Cost β”‚ Forever Guarantee
─────────────┼───────────────┼──────────────────
100 KB β”‚ <$0.01 β”‚ 200+ years
1 MB β”‚ ~$0.05 β”‚ 200+ years
10 MB β”‚ ~$0.50 β”‚ 200+ years
100 MB β”‚ ~$5.00 β”‚ 200+ years

One-time cost, permanent storage. No recurring fees!

═══════════════════════════════════════════════════════════════════════════════

πŸŽ“ LEARNING RESOURCES

White Paper: https://arweave.org/yellow-paper.pdf
Docs: https://docs.arweave.org
API: https://arweave.dev/docs
Examples: https://github.com/ArweaveTeam/arweave-js

═══════════════════════════════════════════════════════════════════════════════

πŸš€ NEXT: Check these files for implementation examples:

β€’ lib/utils/ARWEAVE_INTEGRATION_GUIDE.dart (10 examples)
β€’ lib/pages/mint_nft/mint_nft_images.dart (working implementation)
β€’ ARWEAVE_MIGRATION_SUMMARY.md (architecture overview)

═══════════════════════════════════════════════════════════════════════════════
*/

// Quick copy-paste template for new uploads:

/*
import 'package:tree_planting_protocol/utils/services/arweave_services.dart';
import 'package:tree_planting_protocol/providers/arweave_provider.dart';

// In your StatefulWidget:
final arweaveProvider = Provider.of<ArweaveProvider>(context, listen: false);

// Upload file:
final result = await uploadToArweave(
selectedFile,
(isLoading) => setState(() { _isUploading = isLoading; }),
metadata: {
'featureName': 'YourFeature',
'timestamp': DateTime.now().toIso8601String(),
},
);

if (result != null) {
// Success! Use transaction ID
print('πŸŽ‰ Uploaded! TX: ${result.transactionId}');
print('πŸ“Έ View at: ${result.fileUrl}');

// Store on blockchain or database
final mediaFile = MediaFile(
id: 'feature_file_1',
provider: StorageProvider.arweave,
transactionId: result.transactionId,
fileUrl: result.fileUrl,
fileSize: result.fileSize,
uploadedAt: result.uploadedAt,
);
}
*/
Loading