Skip to content

Storage Costs

Understanding storage costs helps you budget effectively and avoid service interruptions. This guide explains how to calculate costs and fund your account for Filecoin storage.

Storage operates on a pay-per-epoch model where you deposit USDFC tokens and set allowances that control how much the storage service can spend.

ComponentCostNotes
Storage$2.50/TiB/monthMinimum $0.06/month per data set (~24.567 GiB threshold)
CDN Egress$14/TiB downloaded1 USDFC top-up ≈ 71.5 GiB of downloads
CDN Setup1 USDFC (one-time)Per data set; reusing existing data sets incurs no cost

Pricing Logic:

  • Storage < 24.567 GiB: Minimum $0.06/month applies
  • Storage ≥ 24.567 GiB: Actual cost (bytes / TiB) × $2.50/month
  • CDN data sets require 1 USDFC setup on first creation only
  • CDN egress credits can be topped up anytime

Example 1: NFT Collection (10,000 × 5 KiB ≈ 48.82 MiB)

// 48.82 MiB less than 24.567 GiB threshold
// Price is $0.06/month
const
const PRICE_PER_MONTH: 0.06
PRICE_PER_MONTH
= 0.06;
const
const months: 24
months
= 24;
const
const PRICE_FOR_24_MONTHS: number
PRICE_FOR_24_MONTHS
=
const PRICE_PER_MONTH: 0.06
PRICE_PER_MONTH
* 24; // 1.44 USDFC
DurationTotal Cost
1 month0.06 USDFC
24 months1.44 USDFC

Example 2: User Content Platform with CDN

  • Storage: 1,000 users × 100 MiB ≈ 100,000 MiB
  • Traffic: 1,000 users × 100 MiB/month ≈ 100,000 MiB/month egress
const
const STORAGE_PRICE_PER_TIB_PER_MONTH: 2.5
STORAGE_PRICE_PER_TIB_PER_MONTH
= 2.5; // $2.50/TiB/month
const
const CDN_EGRESS_PRICE_PER_TIB: 14
CDN_EGRESS_PRICE_PER_TIB
= 14; // $14/TiB downloaded
const
const storageMiB: 100000
storageMiB
= 100_000;
const
const egressMiB: 100000
egressMiB
= 100_000;
// Storage: 100,000 MiB ≈ 0.0953 TiB
const
const storageTiB: number
storageTiB
=
const storageMiB: 100000
storageMiB
/ 1024 / 1024;
// Egress: 100,000 MiB ≈ 0.0953 TiB
const
const egressTiB: number
egressTiB
=
const egressMiB: 100000
egressMiB
/ 1024 / 1024;
// Storage cost per month: 0.0953 TiB × $2.50 ≈ $0.238/month
const
const storageCostPerMonth: number
storageCostPerMonth
=
const storageTiB: number
storageTiB
*
const STORAGE_PRICE_PER_TIB_PER_MONTH: 2.5
STORAGE_PRICE_PER_TIB_PER_MONTH
;
// Egress cost per month: 0.0953 TiB × $14 ≈ $1.334/month
const
const egressCostPerMonth: number
egressCostPerMonth
=
const egressTiB: number
egressTiB
*
const CDN_EGRESS_PRICE_PER_TIB: 14
CDN_EGRESS_PRICE_PER_TIB
;
// Total cost per month: $0.238/month + $1.334/month ≈ $1.572/month
const
const totalCostPerMonth: number
totalCostPerMonth
=
const storageCostPerMonth: number
storageCostPerMonth
+
const egressCostPerMonth: number
egressCostPerMonth
;
// Total cost for 24 months: $1.572/month × 24 ≈ $37.728
const
const totalCostFor24Months: number
totalCostFor24Months
=
const totalCostPerMonth: number
totalCostPerMonth
* 24;
Cost ComponentPer Month24 Months
Storage≈ 0.238 USDFC≈ 5.71 USDFC
CDN Egress≈ 1.334 USDFC≈ 32.016 USDFC
Total≈ 1.572 USDFC≈ 37.728 USDFC

Before uploading, approve the WarmStorage operator and fund your account. FWSS requires a 30-day prepayment buffer—when your balance drops below 30 days, the provider may remove your data.

Approval Components:

ComponentPurposeFormula When Adding Storage
Deposit AmountUSDFC tokens for storage durationTotal cost for desired months
Rate AllowanceMax spending per epoch (cumulative)currentRateUsed + newRate
Lockup Allowance30-day prepayment buffer (cumulative)currentLockupUsed + (newRate × 86,400)
Max Lockup PeriodSafety limit on locked fundsconstant of 86,400 epochs (30 days)

Learn how to calculate storage costs, required operator allowances and fund your account for future storage needs.

In this guide we will calculate the costs for a 1 GiB storage capacity for 12 months.

Get pricing information and calculate the cost per epoch for your storage capacity:

// Get pricing structure
const
const warmStorageAddress: string
warmStorageAddress
= await
const synapse: Synapse
synapse
.
Synapse.getWarmStorageAddress(): string
getWarmStorageAddress
();
const
const warmStorageService: WarmStorageService
warmStorageService
= await
class WarmStorageService
WarmStorageService
.
WarmStorageService.create(provider: Provider, warmStorageAddress: string): Promise<WarmStorageService>
create
(
const synapse: Synapse
synapse
.
Synapse.getProvider(): Provider
getProvider
(),
const warmStorageAddress: string
warmStorageAddress
);
const {
const minimumPricePerMonth: bigint
minimumPricePerMonth
,
const epochsPerMonth: bigint
epochsPerMonth
,
const pricePerTiBPerMonthNoCDN: bigint
pricePerTiBPerMonthNoCDN
} =
await
const warmStorageService: WarmStorageService
warmStorageService
.
WarmStorageService.getServicePrice(): Promise<ServicePriceInfo>
getServicePrice
();
// Calculate base cost per month
const
const bytesToStore: bigint
bytesToStore
=
const SIZE_CONSTANTS: {
readonly KiB: 1024n;
readonly MiB: bigint;
readonly GiB: bigint;
readonly TiB: bigint;
readonly PiB: bigint;
readonly MAX_UPLOAD_SIZE: number;
readonly MIN_UPLOAD_SIZE: 127;
readonly DEFAULT_UPLOAD_BATCH_SIZE: 32;
}
SIZE_CONSTANTS
.
type GiB: bigint
GiB
; // 1 GiB
let
let pricePerMonth: bigint
pricePerMonth
=
(
const pricePerTiBPerMonthNoCDN: bigint
pricePerTiBPerMonthNoCDN
*
var BigInt: BigIntConstructor
(value: bigint | boolean | number | string) => bigint
BigInt
(
const bytesToStore: bigint
bytesToStore
)) /
var BigInt: BigIntConstructor
(value: bigint | boolean | number | string) => bigint
BigInt
(
const SIZE_CONSTANTS: {
readonly KiB: 1024n;
readonly MiB: bigint;
readonly GiB: bigint;
readonly TiB: bigint;
readonly PiB: bigint;
readonly MAX_UPLOAD_SIZE: number;
readonly MIN_UPLOAD_SIZE: 127;
readonly DEFAULT_UPLOAD_BATCH_SIZE: 32;
}
SIZE_CONSTANTS
.
type TiB: bigint
TiB
);
// Apply minimum pricing if needed
if (
let pricePerMonth: bigint
pricePerMonth
<
const minimumPricePerMonth: bigint
minimumPricePerMonth
) {
let pricePerMonth: bigint
pricePerMonth
=
const minimumPricePerMonth: bigint
minimumPricePerMonth
;
}
// Calculate per-epoch cost
const
const pricePerEpoch: bigint
pricePerEpoch
=
let pricePerMonth: bigint
pricePerMonth
/
const epochsPerMonth: bigint
epochsPerMonth
;
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("Monthly cost:",
let pricePerMonth: bigint
pricePerMonth
);
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("Per-epoch cost:",
const pricePerEpoch: bigint
pricePerEpoch
);

Calculate cumulative allowances for your new storage, accounting for existing usage.

// Define storage duration in months (minimum 1 month)
const
const persistencePeriodInMonths: 12
persistencePeriodInMonths
= 12;
// Check if creating a new CDN dataset (creates context to determine if one exists)
const
const storageContext: StorageContext
storageContext
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.createContext(options?: StorageServiceOptions): Promise<StorageContext>
createContext
({
StorageServiceOptions.withCDN?: boolean
withCDN
: true,
StorageServiceOptions.metadata?: Record<string, string>
metadata
: {
type Application: string
Application
: "MyApp",
type Version: string
Version
: "1.0.0" },
});
const
const newCDNDataSetNeeded: boolean
newCDNDataSetNeeded
=
const storageContext: StorageContext
storageContext
.
StorageContext.dataSetId: number | undefined
dataSetId
=== null;
const
const warmStorageDefaultLockupPeriod: 30n
warmStorageDefaultLockupPeriod
=
const TIME_CONSTANTS: {
readonly EPOCH_DURATION: 30;
readonly EPOCHS_PER_DAY: 2880n;
readonly EPOCHS_PER_MONTH: 86400n;
readonly DAYS_PER_MONTH: 30n;
readonly DEFAULT_LOCKUP_DAYS: 30n;
}
TIME_CONSTANTS
.
type DEFAULT_LOCKUP_DAYS: 30n
DEFAULT_LOCKUP_DAYS
; // 30 days
// Calculate total cost and lockup needed for THIS storage addition
const
const cdnDataSetCreationCost: bigint
cdnDataSetCreationCost
= 10n ** 18n; // 1 USDFC
let
let totalCostNeeded: bigint
totalCostNeeded
=
const pricePerMonth: bigint
pricePerMonth
*
var BigInt: BigIntConstructor
(value: bigint | boolean | number | string) => bigint
BigInt
(
const persistencePeriodInMonths: 12
persistencePeriodInMonths
);
let
let lockupNeeded: bigint
lockupNeeded
=
const pricePerMonth: bigint
pricePerMonth
*
const warmStorageDefaultLockupPeriod: 30n
warmStorageDefaultLockupPeriod
;
if (
const newCDNDataSetNeeded: boolean
newCDNDataSetNeeded
) {
let lockupNeeded: bigint
lockupNeeded
+=
const cdnDataSetCreationCost: bigint
cdnDataSetCreationCost
;
let totalCostNeeded: bigint
totalCostNeeded
+=
const cdnDataSetCreationCost: bigint
cdnDataSetCreationCost
;
}
// Get current approval status (what's already being used)
const [
const approval: {
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}
approval
,
const accountInfo: {
funds: bigint;
lockupCurrent: bigint;
lockupRate: bigint;
lockupLastSettledAt: bigint;
availableFunds: bigint;
}
accountInfo
] = await
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
PromiseConstructor.all<[Promise<{
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}>, Promise<{
funds: bigint;
lockupCurrent: bigint;
lockupRate: bigint;
lockupLastSettledAt: bigint;
availableFunds: bigint;
}>]>(values: [Promise<{
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}>, Promise<{
funds: bigint;
lockupCurrent: bigint;
lockupRate: bigint;
lockupLastSettledAt: bigint;
availableFunds: bigint;
}>]): Promise<...> (+1 overload)

Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

@paramvalues An array of Promises.

@returnsA new Promise.

all
([
const synapse: Synapse
synapse
.
Synapse.payments: PaymentsService
payments
.
PaymentsService.serviceApproval(service: string, token?: TokenIdentifier): Promise<{
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}>
serviceApproval
(
const warmStorageAddress: string
warmStorageAddress
),
const synapse: Synapse
synapse
.
Synapse.payments: PaymentsService
payments
.
PaymentsService.accountInfo(token?: TokenIdentifier): Promise<{
funds: bigint;
lockupCurrent: bigint;
lockupRate: bigint;
lockupLastSettledAt: bigint;
availableFunds: bigint;
}>
accountInfo
(
const TOKENS: {
readonly USDFC: "USDFC";
readonly FIL: "FIL";
}
TOKENS
.
type USDFC: "USDFC"
USDFC
),
]);
// Calculate cumulative allowances: existing usage + new requirements
// This ensures the operator can spend for ALL your datasets
const
const lockupAllowanceNeeded: bigint
lockupAllowanceNeeded
=
const approval: {
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}
approval
.
lockupUsed: bigint
lockupUsed
+
let lockupNeeded: bigint
lockupNeeded
;
const
const rateAllowanceNeeded: bigint
rateAllowanceNeeded
=
const approval: {
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}
approval
.
rateUsed: bigint
rateUsed
+
const pricePerEpoch: bigint
pricePerEpoch
;
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("New lockup needed:",
let lockupNeeded: bigint
lockupNeeded
);
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("Cumulative lockup allowance needed:",
const lockupAllowanceNeeded: bigint
lockupAllowanceNeeded
);
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("Cumulative rate allowance needed:",
const rateAllowanceNeeded: bigint
rateAllowanceNeeded
);

Check balances, calculate deposit amount, and execute the appropriate transaction:

// Calculate deposit amount needed
const
const depositAmountNeeded: bigint
depositAmountNeeded
=
const totalCostNeeded: bigint
totalCostNeeded
>
const accountInfo: {
funds: bigint;
lockupCurrent: bigint;
lockupRate: bigint;
lockupLastSettledAt: bigint;
availableFunds: bigint;
}
accountInfo
.
availableFunds: bigint
availableFunds
?
const totalCostNeeded: bigint
totalCostNeeded
-
const accountInfo: {
funds: bigint;
lockupCurrent: bigint;
lockupRate: bigint;
lockupLastSettledAt: bigint;
availableFunds: bigint;
}
accountInfo
.
availableFunds: bigint
availableFunds
: 0n;
// Check if allowances are sufficient
const
const sufficient: boolean
sufficient
=
const rateAllowanceNeeded: bigint
rateAllowanceNeeded
<=
const approval: {
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}
approval
.
rateAllowance: bigint
rateAllowance
&&
const lockupAllowanceNeeded: bigint
lockupAllowanceNeeded
<=
const approval: {
isApproved: boolean;
rateAllowance: bigint;
rateUsed: bigint;
lockupAllowance: bigint;
lockupUsed: bigint;
maxLockupPeriod: bigint;
}
approval
.
lockupAllowance: bigint
lockupAllowance
;
// Verify wallet balance
const
const walletBalance: bigint
walletBalance
= await
const synapse: Synapse
synapse
.
Synapse.payments: PaymentsService
payments
.
PaymentsService.walletBalance(token?: TokenIdentifier): Promise<bigint>
walletBalance
(
const TOKENS: {
readonly USDFC: "USDFC";
readonly FIL: "FIL";
}
TOKENS
.
type USDFC: "USDFC"
USDFC
);
if (
const walletBalance: bigint
walletBalance
<
const depositAmountNeeded: bigint
depositAmountNeeded
) {
throw new
var Error: ErrorConstructor
new (message?: string) => Error
Error
("Insufficient USDFC balance in wallet");
}
// Execute appropriate transaction
if (!
const sufficient: boolean
sufficient
&&
const depositAmountNeeded: bigint
depositAmountNeeded
> 0n) {
// Need both deposit and approval
await
const synapse: Synapse
synapse
.
Synapse.payments: PaymentsService
payments
.
PaymentsService.depositWithPermitAndApproveOperator(amount: TokenAmount, operator: string, rateAllowance: TokenAmount, lockupAllowance: TokenAmount, maxLockupPeriod: bigint, token?: TokenIdentifier, deadline?: number | bigint): Promise<TransactionResponse>
depositWithPermitAndApproveOperator
(
const depositAmountNeeded: bigint
depositAmountNeeded
,
const warmStorageAddress: string
warmStorageAddress
,
const rateAllowanceNeeded: bigint
rateAllowanceNeeded
,
const lockupAllowanceNeeded: bigint
lockupAllowanceNeeded
,
const TIME_CONSTANTS: {
readonly EPOCH_DURATION: 30;
readonly EPOCHS_PER_DAY: 2880n;
readonly EPOCHS_PER_MONTH: 86400n;
readonly DAYS_PER_MONTH: 30n;
readonly DEFAULT_LOCKUP_DAYS: 30n;
}
TIME_CONSTANTS
.
type EPOCHS_PER_MONTH: 86400n
EPOCHS_PER_MONTH
);
} else if (!
const sufficient: boolean
sufficient
) {
// Only need approval update
await
const synapse: Synapse
synapse
.
Synapse.payments: PaymentsService
payments
.
PaymentsService.approveService(service: string, rateAllowance: TokenAmount, lockupAllowance: TokenAmount, maxLockupPeriod: TokenAmount, token?: TokenIdentifier): Promise<TransactionResponse>
approveService
(
const warmStorageAddress: string
warmStorageAddress
,
const rateAllowanceNeeded: bigint
rateAllowanceNeeded
,
const lockupAllowanceNeeded: bigint
lockupAllowanceNeeded
,
const TIME_CONSTANTS: {
readonly EPOCH_DURATION: 30;
readonly EPOCHS_PER_DAY: 2880n;
readonly EPOCHS_PER_MONTH: 86400n;
readonly DAYS_PER_MONTH: 30n;
readonly DEFAULT_LOCKUP_DAYS: 30n;
}
TIME_CONSTANTS
.
type EPOCHS_PER_MONTH: 86400n
EPOCHS_PER_MONTH
);
} else if (
const depositAmountNeeded: bigint
depositAmountNeeded
> 0n) {
// Only need deposit
await
const synapse: Synapse
synapse
.
Synapse.payments: PaymentsService
payments
.
PaymentsService.depositWithPermit(amount: TokenAmount, token?: TokenIdentifier, deadline?: number | bigint): Promise<TransactionResponse>
depositWithPermit
(
const depositAmountNeeded: bigint
depositAmountNeeded
,
const warmStorageAddress: string
warmStorageAddress
);
}
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("Account funded successfully");