Configuring Networks and Chains
A convenient way to configure and work with different EVM networks and their corresponding chain configurations. The Chain
class represents a specific chain, and the Chains
class offers a predefined set of popular networks and their chain configurations.
The Chain Class
The Chain
class encapsulates the configuration details of a specific EVM network. It includes the following properties:
chainId
: The unique identifier of the chain.explorer
: The URL of the block explorer for this chain.entrypoint
: The address of the EntryPoint contract on this chain.accountFactory
: The address of the AccountFactory contract on this chain (required).jsonRpcUrl
: The URL of the JSON-RPC endpoint for this chain.bundlerUrl
: The URL of the bundler service for this chain.paymasterUrl
: The URL of the paymaster service for this chain (optional).testnet
: A boolean flag indicating whether the chain is a testnet.
You can create a new instance of the Chain
class by providing the required properties:
final chain = Chain(
chainId: 1,
explorer: 'https://etherscan.io',
entrypoint: EntryPointAddress('0x...'),
accountFactory: EthereumAddress('0x...'),
jsonRpcUrl: 'https://mainnet.infura.io/v3/...',
bundlerUrl: 'https://bundler.example.com',
paymasterUrl: 'https://paymaster.example.com',
);
The Chains Class
The Chains
class provides a predefined set of popular EVM networks and their corresponding chain configurations. You can obtain the Chain
instance for a specific network using the getChain
method:
final mainnetChain = Chains.getChain(Network.ethereum);
final sepoliaChain = Chains.getChain(Network.sepolia);
The Network
enum represents the available networks, including:
- Mainnet networks:
ethereum
,polygon
,optimism
,base
,arbitrum
,linea
,fuse
,scroll
- Testnets:
sepolia
,baseTestnet
Each predefined network has its corresponding chain configuration, including the chainId
, explorer
, jsonRpcUrl
, and entrypoint
address.
You can access other chain-specific constants, such as contract addresses, through the Constants
class:
import 'package:variance_dart/variance_dart.dart';
final entrypointv06Address = Constants.entrypointv06;
final simpleAccountFactoryAddressv07 = Constants.simpleAccountFactoryAddressv07;
Usage
final mainnetChain = Chains.getChain(Network.ethereum);
final walletFactory = SmartWalletFactory(mainnetChain, signer);
final salt = Uint256.zero;
final wallet = await walletFactory.createSafeAccount(salt);
print("wallet created ${wallet.address.hex} ");