Network

public enum Network : Sendable

Represents a Stellar network and its network passphrase.

Each Stellar network (public, testnet, futurenet, or custom) has a unique network passphrase that is used to derive transaction IDs. The network passphrase is hashed together with the transaction envelope to ensure transactions created for one network cannot be replayed on another network.

You must specify the correct network when building and submitting transactions. Using the wrong network passphrase will result in transaction rejection.

Example:

// Build transaction for public network
let transaction = try Transaction(
    sourceAccount: account,
    operations: [operation],
    memo: .none
)
try transaction.sign(keyPair: keyPair, network: .public)

// Build transaction for testnet
try transaction.sign(keyPair: keyPair, network: .testnet)

// Build transaction for custom network
try transaction.sign(keyPair: keyPair, network: .custom(passphrase: "My Custom Network"))

See also:

  • The Stellar public network (mainnet) - “Public Global Stellar Network ; September 2015”

    Declaration

    Swift

    case `public`
  • The Stellar test network - “Test SDF Network ; September 2015”

    Declaration

    Swift

    case testnet
  • The Stellar future network for testing upcoming features - “Test SDF Future Network ; October 2022”

    Declaration

    Swift

    case futurenet
  • A custom network with a user-defined passphrase

    Declaration

    Swift

    case custom(passphrase: String)

passphrase, Network Id

  • The SHA256 hash of the network passphrase.

    This network ID is used when signing transactions and verifying signatures. It ensures that transactions cannot be replayed across different networks.

    Declaration

    Swift

    var networkId: Data { get }
  • The network passphrase string for this network.

    Returns the standard passphrase for Stellar’s public, testnet, or futurenet, or the custom passphrase for custom networks.

    Declaration

    Swift

    var passphrase: String { get }