addEthereumConnector

Add Ethereum connector to the Dynamic client for blockchain functionality.
public func addEthereumConnector(
    to client: DynamicClient,
    networkConfigProvider: NetworkConfigurationProvider,
    initialChainId: Int
) async throws

Parameters

  • client (DynamicClient) - Initialized Dynamic client
  • networkConfigProvider (NetworkConfigurationProvider) - Network configuration provider
  • initialChainId (Int) - Initial chain ID to connect to

Example

do {
    try await addEthereumConnector(
        to: dynamicClient,
        networkConfigProvider: GenericNetworkConfigurationProvider(),
        initialChainId: 84532  // Base Testnet
    )
    print("✅ Ethereum connector added successfully")
} catch {
    print("❌ Failed to add Ethereum connector: \(error)")
}

GenericNetworkConfigurationProvider

Default network configuration provider for Ethereum networks.
public class GenericNetworkConfigurationProvider: NetworkConfigurationProvider {
    // Implementation details
}

Usage

let networkProvider = GenericNetworkConfigurationProvider()

try await addEthereumConnector(
    to: dynamicClient,
    networkConfigProvider: networkProvider,
    initialChainId: 84532
)

SupportedEthereumNetwork

Enumeration of supported Ethereum networks with their configurations.
public enum SupportedEthereumNetwork {
    case sepoliaTestnet
    case mainnet
    // ... other networks

    public var chainConfig: ChainConfig
}

Available Networks

  • sepoliaTestnet - Ethereum Sepolia testnet (Chain ID: 11155111)
  • mainnet - Ethereum mainnet (Chain ID: 1)

Example

// Get Sepolia testnet configuration
let sepolia = SupportedEthereumNetwork.sepoliaTestnet.chainConfig
print("Sepolia Chain ID: \(sepolia.chainId)") // 11155111

// Get mainnet configuration
let mainnet = SupportedEthereumNetwork.mainnet.chainConfig
print("Mainnet Chain ID: \(mainnet.chainId)") // 1

fromChainId

Get a supported network from chain ID.
public static func fromChainId(_ chainId: BigUInt) -> SupportedEthereumNetwork?

Parameters

  • chainId (BigUInt) - Chain ID to look up

Returns

  • SupportedEthereumNetwork? - Network if supported, nil otherwise

Example

let chainId = BigUInt(11155111) // Sepolia

if let supportedNetwork = SupportedEthereumNetwork.fromChainId(chainId) {
    let networkConfig = supportedNetwork.chainConfig
    print("Network: \(networkConfig.name)")
    print("Chain ID: \(networkConfig.chainId)")
}

ChainConfig

Configuration for a blockchain network.
public struct ChainConfig {
    public let chainId: BigUInt
    public let name: String
    public let blockExplorerUrls: [String]
    // ... other properties
}

Properties

  • chainId (BigUInt) - Chain ID of the network
  • name (String) - Human-readable network name
  • blockExplorerUrls ([String]) - Array of block explorer URLs

Example

let sepoliaConfig = SupportedEthereumNetwork.sepoliaTestnet.chainConfig
print("Chain ID: \(sepoliaConfig.chainId)")
print("Name: \(sepoliaConfig.name)")
print("Explorer: \(sepoliaConfig.blockExplorerUrls.first ?? "N/A")")

EthereumTransaction

Transaction object for sending Ethereum transactions.
public struct EthereumTransaction {
    public let from: EthereumAddress
    public let to: EthereumAddress
    public let value: BigUInt
    public let data: Data
    public let nonce: BigUInt?
    public let gasPrice: BigUInt
    public let gasLimit: BigUInt
    public let chainId: BigUInt

    public init(
        from: EthereumAddress,
        to: EthereumAddress,
        value: BigUInt,
        data: Data,
        nonce: BigUInt?,
        gasPrice: BigUInt,
        gasLimit: BigUInt,
        chainId: BigUInt
    )
}

Initialization

public init(
    from: EthereumAddress,
    to: EthereumAddress,
    value: BigUInt,
    data: Data,
    nonce: BigUInt?,
    gasPrice: BigUInt,
    gasLimit: BigUInt,
    chainId: BigUInt
)

Parameters

  • from (EthereumAddress) - Sender address
  • to (EthereumAddress) - Recipient address
  • value (BigUInt) - Amount to send in Wei
  • data (Data) - Transaction data (empty for ETH transfers)
  • nonce (BigUInt?) - Transaction nonce (nil for auto)
  • gasPrice (BigUInt) - Gas price in Wei
  • gasLimit (BigUInt) - Gas limit
  • chainId (BigUInt) - Chain ID of the network

Example

let fromAddress = ethereumWallet.address
let toAddress = EthereumAddress("0xRecipientAddress")
let amount = BigUInt(1000000000000000000) // 1 ETH in wei
let gasPrice = try await networkClient.eth_gasPriceBigInt()
let gasLimit = BigUInt(21_000) // Standard ETH transfer
let chainId = SupportedEthereumNetwork.sepoliaTestnet.chainConfig.chainId

let transaction = EthereumTransaction(
    from: fromAddress,
    to: toAddress,
    value: amount,
    data: Data(),
    nonce: nil,
    gasPrice: gasPrice,
    gasLimit: gasLimit,
    chainId: chainId
)

EthereumAddress

Ethereum address representation.
public struct EthereumAddress {
    public init(_ address: String) throws

    public func asString() -> String
}

Initialization

public init(_ address: String) throws

Parameters

  • address (String) - Ethereum address string

Example

do {
    let address = try EthereumAddress("0x1234567890abcdef1234567890abcdef12345678")
    let addressString = address.asString()
    print("Address: \(addressString)")
} catch {
    print("Invalid address: \(error)")
}

Methods

asString

Get the string representation of the address.
public func asString() -> String

Returns

  • String - Address in string format

Example

let address = try EthereumAddress("0x1234567890abcdef1234567890abcdef12345678")
let addressString = address.asString()
print("Address: \(addressString)")

BaseEthereumClient

Client for interacting with Ethereum networks.
public protocol BaseEthereumClient {
    func eth_gasPriceBigInt() async throws -> BigUInt
    // ... other methods
}

Methods

eth_gasPriceBigInt

Get the current gas price for the network.
func eth_gasPriceBigInt() async throws -> BigUInt
Returns
  • BigUInt - Current gas price in Wei
Example
let networkClient: BaseEthereumClient = try await ethereumWallet.getNetworkClient(for: chainId)

do {
    let gasPrice = try await networkClient.eth_gasPriceBigInt()
    print("Current gas price: \(gasPrice) wei")
} catch {
    print("Failed to get gas price: \(error)")
}

BlockParameter

Block parameter for queries.
public enum BlockParameter {
    case Latest
    case Earliest
    case Pending
    case Number(BigUInt)
}

Values

  • Latest - Latest block
  • Earliest - Earliest block
  • Pending - Pending block
  • Number(BigUInt) - Specific block number

Example

// Get latest balance
let balance = try await ethereumWallet.getBalance(.Latest)

// Get balance at specific block
let blockNumber = BigUInt(1000000)
let balanceAtBlock = try await ethereumWallet.getBalance(.Number(blockNumber))