@@ -7,7 +7,17 @@ description: "createFlowClient function documentation."
77
88# createFlowClient
99
10- Creates a Flow client instance with authentication, transaction, and query capabilities.
10+ Creates a Flow client instance with scoped configuration.
11+
12+ This function decouples FCL functions from the global state and constructs a new SDK client
13+ instance bound to a custom context. This allows for better modularity and supports multiple
14+ FCL instances in the same application, each with their own isolated configuration and state.
15+
16+ Benefits of scoped configuration:
17+ - ** Isolation** : Each client has its own configuration, storage, and state
18+ - ** Multi-tenancy** : Connect to different Flow networks simultaneously
19+ - ** Type Safety** : Configuration is validated at compile time via TypeScript
20+ - ** Testing** : Easy to create isolated client instances for testing
1121
1222## Import
1323
@@ -27,6 +37,34 @@ import { createFlowClient } from "@onflow/fcl"
2737createFlowClient (params )
2838```
2939
40+ ## Usage
41+
42+ ``` typescript
43+ // Multiple isolated clients for different networks
44+ import { createFlowClient } from " @onflow/fcl"
45+
46+ const mainnetClient = createFlowClient ({
47+ accessNodeUrl: " https://rest-mainnet.onflow.org" ,
48+ flowNetwork: " mainnet" ,
49+ appDetailTitle: " My App (Mainnet)" ,
50+ })
51+
52+ const testnetClient = createFlowClient ({
53+ accessNodeUrl: " https://rest-testnet.onflow.org" ,
54+ flowNetwork: " testnet" ,
55+ appDetailTitle: " My App (Testnet)" ,
56+ })
57+
58+ // Query both networks simultaneously
59+ const [mainnetBlock, testnetBlock] = await Promise .all ([
60+ mainnetClient .query ({
61+ cadence: ` access(all) fun main(): UInt64 { return getCurrentBlock().height } ` ,
62+ }),
63+ testnetClient .query ({
64+ cadence: ` access(all) fun main(): UInt64 { return getCurrentBlock().height } ` ,
65+ }),
66+ ])
67+ ```
3068
3169## Parameters
3270
@@ -122,6 +160,6 @@ export interface FlowClientConfig {
122160` ` `
123161
124162
125- A Flow client object with many methods for interacting with the Flow blockchain
163+ A Flow client object with methods for interacting with the Flow blockchain
126164
127165---
0 commit comments