You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tools/clients/fcl-js/index.md
+76-66
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,26 @@ sidebar_position: 3
4
4
5
5
# Flow Client Library (FCL)
6
6
7
-
The Flow Client Library (FCL) JS is a package used to interact with user wallets and the Flow blockchain. When using FCL for authentication, dapps are able to support all FCL-compatible wallets on Flow and their users without any custom integrations or changes needed to the dapp code.
7
+
## 🌟 What is FCL?
8
8
9
-
It was created to make developing applications that connect to the Flow blockchain easy and secure. It defines a standardized set of communication patterns between wallets, applications, and users that is used to perform a wide variety of actions for your dapp. FCL also offers a full featured SDK and utilities to interact with the Flow blockchain.
9
+
The **Flow Client Library (FCL) JS** is a package designed to facilitate interactions between dapps, wallets, and the Flow blockchain. It provides a standardized way for applications to connect with users and their wallets, **eliminating the need for custom integrations**.
10
10
11
-
While FCL itself is a concept and standard, FCL JS is the javascript implementation of FCL and can be used in both browser and server environments. All functionality for connecting and communicating with wallet providers is restricted to the browser. We also have FCL Swift implementation for iOS, see [FCL Swift](https://github.com/zed-io/fcl-swift) contributed by [@lmcmz](https://github.com/lmcmz).
11
+
### 🔑 Key Features:
12
+
- 🔌 **Universal Wallet Support** – Works seamlessly with all FCL-compatible wallets, making authentication simple.
13
+
- 🔐 **Secure Authentication** – Standardized authentication flow ensures a smooth user experience.
14
+
- ⚡ **Blockchain Interactions** – Enables querying, mutating, and interacting with smart contracts on Flow.
- 🌍 **Flexible Environment** – Can run in both browser and server environments, though wallet interactions are browser-only.
12
17
13
-
---
18
+
FCL was created to make building Flow-connected applications **easy, secure, and scalable** by defining **standardized communication patterns** between wallets, applications, and users.
19
+
20
+
For iOS, we also offer [FCL Swift](https://github.com/Outblock/fcl-swift).
14
21
22
+
---
15
23
## Getting Started
16
24
17
25
### Requirements
18
-
19
-
- Node version `v12.0.0 or higher`.
26
+
- Node version `v12.0.0 or higher`.
20
27
21
28
### Installation
22
29
@@ -29,156 +36,159 @@ npm i -S @onflow/fcl
29
36
```shell
30
37
yarn add @onflow/fcl
31
38
```
32
-
33
39
#### Importing
34
40
35
41
**ES6**
36
-
37
42
```js
38
-
import*asfclfrom'@onflow/fcl';
43
+
import*asfclfrom"@onflow/fcl";
39
44
```
40
-
41
45
**Node.js**
42
-
43
46
```js
44
-
constfcl=require('@onflow/fcl');
47
+
constfcl=require("@onflow/fcl");
45
48
```
46
-
47
49
---
48
-
49
50
## FCL for Dapps
50
-
51
51
#### Wallet Interactions
52
52
53
-
-_Wallet Discovery_ and _Sign-up/Login_: Onboard users with ease. Never worry about supporting multiple wallets.
54
-
Authenticate users with any [FCL compatible wallet](./index.md#current-wallet-providers).
55
-
53
+
-*Wallet Discovery* and *Sign-up/Login*: Onboard users with ease. Never worry about supporting multiple wallets.
54
+
Authenticate users with any [FCL compatible wallet](#current-wallet-providers).
56
55
```js
57
56
// in the browser
58
-
import*asfclfrom'@onflow/fcl';
57
+
import*asfclfrom"@onflow/fcl"
59
58
60
59
fcl.config({
61
-
'discovery.wallet':'https://fcl-discovery.onflow.org/testnet/authn', // Endpoint set to Testnet
62
-
});
60
+
"discovery.wallet":"https://fcl-discovery.onflow.org/testnet/authn", // Endpoint set to Testnet
61
+
})
63
62
64
-
fcl.authenticate();
63
+
fcl.authenticate()
65
64
```
66
-
67
65

68
66
69
-
> **Note**: A [Dapper Wallet](https://meetdapper.com/developers) developer account is required. To enable Dapper Wallet inside FCL, you need to [follow this guide](https://docs.meetdapper.com/quickstart).
67
+
> **Note**: A [Dapper Wallet](https://meetdapper.com/developers) developer account is required. To enable Dapper Wallet inside FCL, you need to [follow this guide](https://docs.meetdapper.com/get-started).
70
68
71
-
-_Interact with smart contracts_: Authorize transactions via the user's chosen wallet
72
-
-_Prove ownership of a wallet address_: Signing and verifying user signed data
69
+
-*Interact with smart contracts*: Authorize transactions via the user's chosen wallet
70
+
-*Prove ownership of a wallet address*: Signing and verifying user signed data
73
71
74
-
[Learn more about wallet interactions >](./api.md#wallet-interactions)
72
+
[Learn more about wallet interactions >](api.md#wallet-interactions)
75
73
76
74
#### Blockchain Interactions
77
-
78
-
-_Query the chain_: Send arbitrary Cadence scripts to the chain and receive back decoded values
79
-
75
+
-*Query the chain*: Send arbitrary Cadence scripts to the chain and receive back decoded values
80
76
```js
81
-
import*asfclfrom'@onflow/fcl';
77
+
import*asfclfrom"@onflow/fcl";
82
78
83
79
constresult=awaitfcl.query({
84
80
cadence:`
85
-
access(all) fun main(a: Int, b: Int, addr: Address): Int {
81
+
pub fun main(a: Int, b: Int, addr: Address): Int {
[Learn more about on-chain interactions >](./api.md#on-chain-interactions)
112
+
[Learn more about on-chain interactions >](api.md#on-chain-interactions)
119
113
120
114
#### Utilities
121
-
122
115
- Get account details from any Flow address
123
116
- Get the latest block
124
117
- Transaction status polling
125
118
- Event polling
126
119
- Custom authorization functions
127
120
128
-
[Learn more about utilities >](./api.md#pre-built-interactions)
121
+
[Learn more about utilities >](api.md#pre-built-interactions)
129
122
130
-
## Next Steps
123
+
## Typescript Support
131
124
132
-
See the [Flow App Quick Start](../../../build/getting-started/fcl-quickstart.md).
125
+
FCL JS supports TypeScript. If you need to import specific types, you can do so via the [@onflow/typedefs](https://github.com/onflow/fcl-js/tree/master/packages/typedefs) package.
133
126
134
-
See the full [API Reference](./api.md) for all FCL functionality.
127
+
```typescript
128
+
import {CurrentUser} from"@onflow/typedefs"
135
129
136
-
Learn Flow's smart contract language to build any script or transactions: [Cadence](https://cadence-lang.org/docs).
130
+
const newUser:CurrentUser= {
131
+
addr: null,
132
+
cid: null,
133
+
expiresAt: null,
134
+
f_type: 'User',
135
+
f_vsn: '1.0.0',
136
+
loggedIn: null,
137
+
services: []
138
+
}
139
+
```
137
140
138
-
Explore all of Flow [docs and tools](/).
141
+
For all type definitions available, see [this file](https://github.com/onflow/fcl-js/blob/master/packages/typedefs/src/index.ts)
139
142
140
-
---
143
+
## Next Steps
141
144
142
-
## FCL for Wallet Providers
145
+
- See the [Flow App Quick Start](../../../build/getting-started/fcl-quickstart.md).
146
+
- See the full [API Reference](api.md) for all FCL functionality.
147
+
- Learn Flow's smart contract language to build any script or transactions: [Cadence](https://cadence-lang.org).
148
+
- Explore all of Flow [docs and tools](https://developers.flow.com).
143
149
150
+
---
151
+
## FCL for Wallet Providers
144
152
Wallet providers on Flow have the flexibility to build their user interactions and UI through a variety of ways:
145
-
146
153
- Front channel communication via Iframe, pop-up, tab, or extension
147
154
- Back channel communication via HTTP
148
155
149
-
FCL is agnostic to the communication channel and is configured to create both custodial and non-custodial wallets. This enables users to interact with wallet providers without needing to download an app or extension.
156
+
FCL is agnostic to the communication channel and be configured to create both custodial and non-custodial wallets. This enables users to interact with wallet providers without needing to download an app or extension.
150
157
151
-
The communication channels involve responding to a set of pre-defined FCL messages to deliver the requested information to the dapp. Implementing a FCL compatible wallet on Flow is as simple as filling in the responses with the appropriate data when FCL requests them. If using any of the front-channel communication methods, FCL also provides a set of [wallet utilities](https://github.com/onflow/fcl-js/blob/master/packages/fcl/src/wallet-utils/index.js) to simplify this process.
158
+
The communication channels involve responding to a set of pre-defined FCL messages to deliver the requested information to the dapp. Implementing a FCL compatible wallet on Flow is as simple as filling in the responses with the appropriate data when FCL requests them. If using any of the front-channel communication methods, FCL also provides a set of [wallet utilities](https://github.com/onflow/fcl-js/blob/master/packages/fcl-core/src/wallet-utils/index.js) to simplify this process.
-[Dapper Wallet](https://www.meetdapper.com/) (beta access - general availability coming soon)
160
166
161
167
### Wallet Discovery
162
-
163
-
It can be difficult to get users to discover new wallets on a chain. To solve this, we created a wallet discovery service that can be configured and accessed through FCL to display all available Flow wallet providers to the user. This means:
164
-
168
+
It can be difficult to get users to discover new wallets on a chain. To solve this, we created a [wallet discovery service](https://github.com/onflow/fcl-discovery) that can be configured and accessed through FCL to display all available Flow wallet providers to the user. This means:
165
169
- Dapps can display and support all FCL compatible wallets that launch on Flow without needing to change any code
166
170
- Users don't need to sign up for new wallets - they can carry over their existing one to any dapp that uses FCL for authentication and authorization.
167
171
168
-
The discovery feature can be used via API, allowing you to customize your own UI or use the default UI without any additional configuration.
172
+
The discovery feature can be used via API allowing you to customize your own UI or you can use the default UI without any additional configuration.
173
+
174
+
> Note: To get your wallet added to the discovery service, make a PR in [fcl-discovery](https://github.com/onflow/fcl-discovery).
169
175
170
176
### Building a FCL compatible wallet
171
177
172
-
- Read the [wallet guide](https://github.com/onflow/fcl-js/blob/master/packages/fcl/src/wallet-provider-spec/draft-v3.md) to understand the implementation details.
173
-
- Review the architecture of the [Flow Dev Wallet](https://github.com/onflow/fcl-dev-wallet) for an overview.
178
+
- Read the [wallet guide](https://github.com/onflow/fcl-js/blob/master/packages/fcl-core/src/wallet-provider-spec/draft-v4.md) to understand the implementation details.
179
+
- Review the architecture of the [FCL dev wallet](https://github.com/onflow/fcl-dev-wallet) for an overview.
174
180
- If building a non-custodial wallet, see the [Account API](https://github.com/onflow/flow-account-api) and the [FLIP](https://github.com/onflow/flow/pull/727) on derivation paths and key generation.
175
181
176
182
---
177
183
178
-
## Support
184
+
## 🛠 Want to Use the Flow SDK Directly?
179
185
180
-
Notice an problem or want to request a feature? [Add an issue](https://github.com/onflow/fcl-js/issues).
186
+
If you prefer to interact with Flow at a **lower level** without using FCL, you can use the [Flow JavaScript SDK](sdk-guidelines.md) directly. The SDK provides raw access to Flow's API for sending transactions, executing scripts, and managing accounts.
181
187
182
-
Discuss FCL with the community on the [forum](https://forum.onflow.org/c/developer-tools/flow-fcl/22).
188
+
FCL is built **on top of the Flow SDK**, making it easier to handle authentication, wallet interactions, and dapp connectivity. Choose the approach that best fits your use case.
189
+
190
+
## Support
183
191
184
-
Join the Flow community on [Discord](https://discord.gg/flow) to keep up to date and to talk to the team.
192
+
- Notice a problem or want to request a feature? [Add an issue](https://github.com/onflow/fcl-js/issues).
193
+
- Join the Flow community on [Discord](https://discord.gg/flow) to keep up to date and to talk to the team.
194
+
- Read the [Contributing Guide](https://github.com/onflow/fcl-js/blob/master/CONTRIBUTING.md) to learn how to contribute to the project.
0 commit comments