createStorageTransaction method
Transaction
createStorageTransaction({})
Build a transaction that creates a storage reservation.
Splits storageCost from the WAL coin and calls reserve_space.
The resulting Storage object can be used with register_blob.
Mirrors TS SDK's createStorage().
Implementation
Transaction createStorageTransaction({
required int encodedSize,
required int epochs,
required String walCoinObjectId,
required BigInt storageCost,
String? walType,
String? owner,
Transaction? transaction,
}) {
final tx = transaction ?? Transaction();
final walCoin = tx.object(walCoinObjectId);
final payment = tx.splitCoins(walCoin, [tx.pure.u64(storageCost)]);
final storage = tx.moveCall(
'$walrusPackageId::system::reserve_space',
arguments: [
tx.object(packageConfig.systemObjectId), // self
tx.pure.u64(BigInt.from(encodedSize)), // storageAmount
tx.pure.u32(epochs), // epochsAhead
payment, // payment: Coin<WAL>
],
);
// Destroy the zero-balance payment coin (Coin<WAL> lacks `drop`).
// reserve_space takes &mut Coin<WAL>, deducting cost and leaving 0.
// Matches TS SDK's #withWal → coin::destroy_zero pattern.
if (walType != null) {
tx.moveCall(
'0x2::coin::destroy_zero',
typeArguments: [walType],
arguments: [payment],
);
}
if (owner != null) {
tx.transferObjects([storage], tx.pure.address(owner));
}
return tx;
}