Skip to main content

Network Configuration

Configure your application for different MultiversX networks.

Available Networks

NetworkChain IDPurpose
Mainnet1Production
DevnetDDevelopment & Testing
TestnetTTesting

Quick Configuration

// Devnet for development
final devnet = GatewayNetworkProvider.devnet();

// Mainnet for production
final mainnet = GatewayNetworkProvider.mainnet();

// Testnet
final testnet = GatewayNetworkProvider.testnet();

Network URLs

Gateway URLs

NetworkURL
Mainnethttps://gateway.multiversx.com
Devnethttps://devnet-gateway.multiversx.com
Testnethttps://testnet-gateway.multiversx.com

API URLs

NetworkURL
Mainnethttps://api.multiversx.com
Devnethttps://devnet-api.multiversx.com
Testnethttps://testnet-api.multiversx.com

Network Configuration Object

Get dynamic network configuration:

final provider = GatewayNetworkProvider.devnet();
final config = await provider.getNetworkConfig();

print('Chain ID: ${config.chainId}');
print('Min gas price: ${config.minGasPrice}');
print('Min gas limit: ${config.minGasLimit}');
print('Gas per data byte: ${config.gasPerDataByte}');
print('Denomination: ${config.denomination}');
print('Rounds per epoch: ${config.roundsPerEpoch}');

NetworkConfig Fields

FieldTypeDescription
chainIdStringNetwork identifier (1, D, T)
minGasPriceintMinimum gas price per unit
minGasLimitintMinimum gas limit for transactions
gasPerDataByteintGas cost per byte of data
gasCostPerMovedBalanceByteintGas for balance transfers
numShardsintNumber of shards in the network
roundDurationintDuration of a round in milliseconds
roundsPerEpochintRounds in each epoch
denominationintToken denomination (18 for EGLD)
topUpFactordoubleTop-up factor for staking rewards
gasPriceModifierStringGas price adjustment modifier
adaptivityboolWhether adaptivity is enabled
hysteresisStringHysteresis value for consensus

Environment-Based Configuration

enum Environment { development, staging, production }

class AppConfig {
final Environment environment;

AppConfig(this.environment);

GatewayNetworkProvider get provider {
switch (environment) {
case Environment.development:
return GatewayNetworkProvider.devnet();
case Environment.staging:
return GatewayNetworkProvider.testnet();
case Environment.production:
return GatewayNetworkProvider.mainnet();
}
}

String get explorerUrl {
switch (environment) {
case Environment.development:
return 'https://devnet-explorer.multiversx.com';
case Environment.staging:
return 'https://testnet-explorer.multiversx.com';
case Environment.production:
return 'https://explorer.multiversx.com';
}
}
}

// Usage
final config = AppConfig(Environment.development);
final provider = config.provider;

Configuration from Environment Variables

import 'dart:io';

GatewayNetworkProvider createProvider() {
final network = Platform.environment['MVX_NETWORK'] ?? 'devnet';

switch (network.toLowerCase()) {
case 'mainnet':
return GatewayNetworkProvider.mainnet();
case 'testnet':
return GatewayNetworkProvider.testnet();
case 'devnet':
default:
return GatewayNetworkProvider.devnet();
}
}

Gas Configuration

Default Gas Values

class GasConfig {
static const egldTransfer = 50000;
static const esdtTransfer = 500000;
static const nftTransfer = 1000000;
static const multiTransfer = 1100000;
static const scCallBase = 5000000;

static int forMultiTransfer(int tokenCount) {
return multiTransfer + (tokenCount * 100000);
}

static int forScCall({
required int argumentCount,
int complexity = 1,
}) {
return scCallBase * complexity + (argumentCount * 50000);
}
}

Dynamic Gas Calculation

int calculateGas({
required NetworkConfig config,
required String data,
required int baseGas,
}) {
final dataGas = data.length * config.gasPerDataByte;
return baseGas + dataGas;
}

Token Identifiers by Network

Wrapped EGLD and common tokens differ per network:

class Tokens {
static const mainnet = _MainnetTokens();
static const devnet = _DevnetTokens();

static TokenConfig forNetwork(String chainId) {
switch (chainId) {
case '1':
return mainnet;
case 'D':
return devnet;
default:
throw ArgumentError('Unknown network: $chainId');
}
}
}

class _MainnetTokens implements TokenConfig {
const _MainnetTokens();


String get wegld => 'WEGLD-bd4d79';


String get usdc => 'USDC-c76f1f';


String get mex => 'MEX-455c57';
}

class _DevnetTokens implements TokenConfig {
const _DevnetTokens();


String get wegld => 'WEGLD-a28c59';


String get usdc => 'USDC-8d4068';


String get mex => 'MEX-dc289c';
}

abstract class TokenConfig {
String get wegld;
String get usdc;
String get mex;
}

Complete Configuration Example

import 'package:abidock_mvx/abidock_mvx.dart';
import 'dart:io';

/// Application configuration
class Config {
final String network;
final GatewayNetworkProvider provider;
final String chainId;
final String explorerUrl;
final TokenConfig tokens;

Config._({
required this.network,
required this.provider,
required this.chainId,
required this.explorerUrl,
required this.tokens,
});

static Future<Config> load() async {
final network = Platform.environment['MVX_NETWORK'] ?? 'devnet';

late GatewayNetworkProvider provider;
late String chainId;
late String explorerUrl;
late TokenConfig tokens;

switch (network.toLowerCase()) {
case 'mainnet':
provider = GatewayNetworkProvider.mainnet();
chainId = '1';
explorerUrl = 'https://explorer.multiversx.com';
tokens = Tokens.mainnet;
break;
case 'testnet':
provider = GatewayNetworkProvider.testnet();
chainId = 'T';
explorerUrl = 'https://testnet-explorer.multiversx.com';
tokens = Tokens.devnet; // Use devnet tokens
break;
case 'devnet':
default:
provider = GatewayNetworkProvider.devnet();
chainId = 'D';
explorerUrl = 'https://devnet-explorer.multiversx.com';
tokens = Tokens.devnet;
}

// Verify connection
final config = await provider.getNetworkConfig();
assert(config.chainId == chainId);

return Config._(
network: network,
provider: provider,
chainId: chainId,
explorerUrl: explorerUrl,
tokens: tokens,
);
}

String txUrl(String hash) => '$explorerUrl/transactions/$hash';
String addressUrl(String address) => '$explorerUrl/accounts/$address';
}

// Usage
void main() async {
final config = await Config.load();

print('Network: ${config.network}');
print('Chain ID: ${config.chainId}');
print('WEGLD: ${config.tokens.wegld}');
}

Next Steps