writeBlob method
Upload a blob in a single call (registers, uploads, certifies).
Requires a SuiAccount signer that can sign transactions directly.
For dApp wallet integration, use writeBlobFlow instead.
The signer must have sufficient WAL tokens in their wallet. WAL coins are resolved automatically from the signer's address.
If walCoinObjectId is provided, uses that specific WAL coin.
Otherwise finds a suitable WAL coin from the signer's account.
If no upload relay is configured, uses direct mode (Phase 3): the blob is encoded client-side and slivers are written directly to storage nodes. This requires encoder (or creates a default WalrusBlobEncoder) and committee (auto-resolved from chain).
Implementation
Future<WriteBlobResult> writeBlob({
required Uint8List blob,
BlobMetadata? metadata,
required int epochs,
required SuiAccount signer,
required bool deletable,
String? owner,
String? walCoinObjectId,
Map<String, String?>? attributes,
}) async {
final effectiveOwner = owner ?? signer.getAddress();
// Load tip config if needed.
await _ensureTipConfig();
if (_relayClient != null) {
// Relay mode: same as Phase 2.
// Auto-compute metadata if not provided. The TS SDK calls
// computeBlobMetadata({ bytes: blob }) in this path.
BlobMetadata effectiveMetadata;
if (metadata != null) {
effectiveMetadata = metadata;
} else {
final systemSt = await _stateReader.systemState();
final nShards = systemSt.nShards;
final encodingType = encoder is WalrusBlobEncoder
? (encoder as WalrusBlobEncoder).encodingType
: kEncodingTypeRS2;
// Run encoding in a separate isolate to avoid blocking the UI
// thread. Fountain code encoding is CPU-intensive.
// Falls back to inline execution on platforms without isolate
// support (web).
try {
// Capture the FFI library path — statics don't transfer across
// isolate boundaries, so we propagate the resolved path explicitly.
final ffiLibPath = WalrusFfiBindings.resolvedPath;
effectiveMetadata = await Isolate.run(() {
if (ffiLibPath != null) {
WalrusFfiBindings.configure(ffiLibPath);
}
final blobEncoder = WalrusBlobEncoder(encodingType: encodingType);
return blobEncoder.computeMetadataSync(blob, nShards);
});
} on UnsupportedError {
// Web platform — run inline.
final blobEncoder = encoder is WalrusBlobEncoder
? encoder as WalrusBlobEncoder
: WalrusBlobEncoder(encodingType: encodingType);
effectiveMetadata = await blobEncoder.computeMetadata(blob, nShards);
}
}
return _writeBlobViaRelay(
blob: blob,
metadata: effectiveMetadata,
epochs: epochs,
signer: signer,
deletable: deletable,
effectiveOwner: effectiveOwner,
walCoinObjectId: walCoinObjectId,
attributes: attributes,
);
} else {
// Direct mode: Phase 3.
return _writeBlobDirect(
blob: blob,
metadata: metadata,
epochs: epochs,
signer: signer,
deletable: deletable,
effectiveOwner: effectiveOwner,
walCoinObjectId: walCoinObjectId,
attributes: attributes,
);
}
}