Skip to main content
Version: 6.23.1

Configuration

Starknet.js has behaviors that can be adjusted through its configurations: config and logger.

Config​

The core global configuration is a singleton object containing case-sensitive global default properties. Each property can be configured before the rest of the code is run to modify their corresponding behavior. When they overlap, constructor and method parameters have higher precedence over the global configuration defaults. Custom keys can also be used to store and use arbitrary values during runtime.

import { config } from 'starknet';

// Set existing or custom global property
config.set('mode', 'DEFAULT');

// Retrieve entire configuration
config.getAll();

// Retrieve single global property
config.get('legacyMode');

// Update (merge) existing configuration with modified or custom property
config.update({ logLevel: 'DEBUG', newKey: 'value' });

// Reset config to initial global configuration
config.reset();

// Delete existing global property
config.delete('newKey');

// Check existence of the global property
config.hasKey('newKey');

Global parameters and Default Global Configuration​

Default global configuration is the initial state that global configuration starts with.

Details can be found in global/constants.ts

  logLevel: 'INFO', // verbosity levels of the system logger, more details under logger
accountTxVersion: ETransactionVersion.V2, // by default use V2 transactions in Account class instances
legacyMode: false, // enable legacy transaction types (note: this could break the code depending on the Starknet version used by the network)

Logger​

Logger is a singleton object through which the Starknet.js logs are managed.

Supported log levels:

DEBUG5show all logs
INFO4show INFO, WARN, ERROR, FATAL
WARN3show WARN, ERROR, FATAL
ERROR2show ERROR, FATAL
FATAL1show only FATAL
OFF0disable logs
import { logger } from 'starknet';

// set custom log level (can also be done using global config)
logger.setLogLevel('WARN');

// get current log level
logger.getLogLevel();

// get a list of all verbosity modes that would be displayed with the current log level
logger.getEnabledLogLevels();

Developers can also use it to add custom logs.

import { logger } from 'starknet';

logger.debug('Debug message', additionalDataObject);
logger.info('Info message', additionalDataObject);
logger.warn('Warn message', additionalDataObject);
logger.error('Error message', additionalDataObject);
logger.fatal('Fatal message', additionalDataObject);