Function createNetwork

  • Creates a customized Stacks network.

    This function allows you to create a network based on a predefined network (mainnet, testnet, devnet, mocknet) or a custom network object. You can also customize the network with an API key or other client options.

    Parameters

    • network: StacksNetwork | "mainnet" | "testnet" | "devnet" | "mocknet"

    Returns StacksNetwork

    Example

    // Create a basic network from a network name
    const network = createNetwork('mainnet');
    const network = createNetwork(STACKS_MAINNET);

    Example

    // Create a network with an API key
    const network = createNetwork('testnet', 'my-api-key');
    const network = createNetwork(STACKS_TESTNET, 'my-api-key');

    Example

    // Create a network with options object
    const network = createNetwork({
    network: 'mainnet',
    apiKey: 'my-api-key',
    });

    Example

    // Create a network with options object with custom API key options
    const network = createNetwork({
    network: 'mainnet',
    apiKey: 'my-api-key',
    host: /\.example\.com$/, // default is /(.*)api(.*)(\.stacks\.co|\.hiro\.so)$/i
    httpHeader: 'x-custom-api-key', // default is 'x-api-key'
    });

    Example

    // Create a network with custom client options
    const network = createNetwork({
    network: STACKS_TESTNET,
    client: {
    baseUrl: 'https://custom-api.example.com',
    fetch: customFetchFunction
    }
    });
  • Parameters

    • network: StacksNetwork | "mainnet" | "testnet" | "devnet" | "mocknet"
    • apiKey: string

    Returns StacksNetwork

  • Parameters

    Returns StacksNetwork

Generated using TypeDoc