Skip to content

Commit 0446ddc

Browse files
committed
fix(tx-sdk): improve guides
1 parent 6559b5e commit 0446ddc

File tree

4 files changed

+136
-72
lines changed

4 files changed

+136
-72
lines changed

docs/network/8-flare-tx-sdk.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ import Tabs from "@theme/Tabs";
99
import TabItem from "@theme/TabItem";
1010
import DocCardList from "@theme/DocCardList";
1111

12-
The Flare Transaction SDK ([`@flarenetwork/flare-tx-sdk`](https://www.npmjs.com/package/@flarenetwork/flare-tx-sdk/)) is the official Node.js toolkit for performing common actions on all Flare networks:
12+
The Flare Transaction SDK ([`@flarenetwork/flare-tx-sdk`](https://www.npmjs.com/package/@flarenetwork/flare-tx-sdk/)) is the official Node.js toolkit for performing common actions on all Flare networks - Flare, Coston2, Songbird, and Coston.
1313

1414
- Claim rewards (FlareDrop, staking, FTSO delegation, rFLR)
1515
- Delegate to FTSO providers
1616
- Stake on the P-chain
1717
- Vote on governance proposals
18-
- Retrieving account and balance information
19-
- Transferring native and wrapped coins
18+
- Retrieve account and balance information
19+
- Transfer native and wrapped coins
2020
- Interact with C-Chain contracts
2121

22-
This guide covers installation, core concepts, and a cookbook of practical tasks.
22+
Explore the following guides to get started:
2323

2424
<DocCardList />
2525

26-
:::tip[Need help?]
26+
:::tip[Need help or found a bug?]
2727

28-
You can raise an issue on the [flare-foundation/flare-tx-sdk](https://github.com/flare-foundation/flare-tx-sdk) GitHub repository.
28+
Open an issue on the [flare-foundation/flare-tx-sdk](https://github.com/flare-foundation/flare-tx-sdk) GitHub repository.
2929

3030
:::

docs/network/flare-tx-sdk/1-getting-started.mdx

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This guide walks you through installation, core concepts, and a quick start exam
2525

2626
Before you start, ensure you have the following:
2727

28-
- [Node.js](https://nodejs.org/en/download) v18 or later
28+
- [Node.js](https://nodejs.org/en/download) v18+ (LTS recommended) and a package manager (npm, yarn, or pnpm)
2929
- A compatible wallet:
3030
- **EIP-1193 wallets** (e.g. MetaMask, WalletConnect)
3131
- **Hardware wallets** (Ledger, Trezor).
@@ -54,15 +54,17 @@ Add the SDK to your project:
5454

5555
## Core concepts
5656

57-
The SDK is built around two key objects:
57+
The SDK separates network logic from account management.
58+
This ensures the same wallet can be used across multiple networks without code changes.
5859

5960
- **`Network`**: Represents the blockchain network you want to connect to. Available networks include:
6061
- `Network.FLARE`
62+
- `Network.COSTON2`
6163
- `Network.SONGBIRD`
6264
- `Network.COSTON`
63-
- `Network.COSTON2`
6465

6566
The `Network` object provides methods to query balances, transfer tokens, claim rewards, and interact with contracts.
67+
It uses Flare's [public RPCs](/network/overview#configuration) by default.
6668

6769
- **`Wallet`**: Represents a user account. The SDK does not store private keys. Instead, it defines a `Wallet` interface which can be implemented by:
6870
- MetaMask and other browser wallets (`EIP1193WalletController`)
@@ -116,30 +118,30 @@ Example output:
116118
}
117119
```
118120

119-
:::note[Units]
121+
:::info[Units]
120122

121123
The SDK uses nats (smallest unit of FLR, equivalent to wei).
122-
Use helpers such as `Amount.nats(x)` for FLR and `Amount.wnats(x)` for WFLR.
124+
Use helpers methods `Amount.nats(x)` for FLR and `Amount.wnats(x)` for WFLR.
123125

124126
:::
125127

126128
## Wallet controllers
127129

128-
The SDK doesn't store keys. Instead, it adapts external signers into a common [`Wallet`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/index.ts) interface via controllers.
129-
This guide shows how to connect EIP-1193 wallets (e.g., MetaMask/WalletConnect), Ledger, Trezor, and how to author a custom wallet.
130+
Wallet controllers adapt third-party wallets into the SDK's [`Wallet`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/index.ts) interface.
131+
They handle signing and address derivation, while your keys remain securely stored in the original wallet.
130132

131-
A controller is a helper class that wraps a standard wallet library (like EIP-1193 for MetaMask or Zondax for Ledger) and produces SDK-compatible objects.
132-
The SDK includes controllers for popular wallet standards to make this easy.
133+
This guide shows how to connect EIP-1193 wallets (e.g., MetaMask/WalletConnect) and hardware wallets (Ledger and Trezor).
133134

134-
:::tip
135+
### EIP-1193 (MetaMask, WalletConnect)
135136

136-
If none of the Wallet controllers here meet your needs, you can implement a [custom wallet controller](/network/flare-tx-sdk/advanced-usage#custom-wallets).
137+
Use the [`EIP1193WalletController`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/eip1193/controller.ts) with any browser wallet that exposes an EIP-1193 provider (e.g., `window.ethereum`).
137138

138-
:::
139+
:::tip[Security]
139140

140-
### EIP-1193 (MetaMask, WalletConnect)
141+
Your private keys **never** leave your wallet.
142+
The SDK only communicates with the wallet for signing.
141143

142-
Use the [`EIP1193WalletController`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/eip1193/controller.ts) with any browser wallet that exposes an EIP-1193 provider (e.g., `window.ethereum`).
144+
:::
143145

144146
```javascript
145147
import { Network, EIP1193WalletController } from "@flarenetwork/flare-tx-sdk";
@@ -177,6 +179,13 @@ async function connectEip1193() {
177179
Use the [`LedgerWalletController`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/ledger/controller.ts).
178180
It supports either Zondax Flare App ([`@zondax/ledger-flare`](https://www.npmjs.com/package/@zondax/ledger-flare)) or Ledger ETH App ([`@ledgerHQ/hw-app-eth`](https://www.npmjs.com/package/@ledgerhq/hw-app-eth)).
179181
182+
:::tip[Security]
183+
184+
Your private keys **never** leave your Ledger device.
185+
The SDK only communicates with the device for signing.
186+
187+
:::
188+
180189
1. **Installation:**
181190
182191
<Tabs groupId="ledger-connector">
@@ -233,7 +242,9 @@ It supports either Zondax Flare App ([`@zondax/ledger-flare`](https://www.npmjs.
233242
import { Eth } from "@ledgerHQ/hw-app-eth"
234243

235244
async function connectLedgerViaEthApp() {
236-
ethApp = Eth(...) // add transport here
245+
// add Ledger transports here
246+
// see https://developers.ledger.com/docs/device-interaction/integration/how_to/transports
247+
const ethApp = Eth(...)
237248
const controller = new LedgerWalletController(null, ethApp);
238249

239250
const path = "m/44'/60'/0'/0/0";
@@ -255,6 +266,13 @@ It supports either Zondax Flare App ([`@zondax/ledger-flare`](https://www.npmjs.
255266
256267
Use the [`TrezorWalletController`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/trezor/controller.ts) with [Trezor Connect](https://connect.trezor.io/9/readme/connect/).
257268
269+
:::tip[Security]
270+
271+
Your private keys **never** leave your Trezor device.
272+
The SDK only communicates with the device for signing.
273+
274+
:::
275+
258276
1. **Installation:**
259277
260278
```bash
@@ -268,7 +286,9 @@ Use the [`TrezorWalletController`](https://github.com/flare-foundation/flare-tx-
268286
import { TrezorWalletController } from "@flarenetwork/flare-tx-sdk";
269287

270288
async function connectTrezor() {
271-
TrezorConnect.init(...) // add manifest here
289+
// add Trezor manifest
290+
// see https://connect.trezor.io/9/methods/other/init/
291+
TrezorConnect.init(...)
272292
const controller = new TrezorWalletController(TrezorConnect);
273293

274294
const path = "m/44'/60'/0'/0/0";
@@ -282,7 +302,14 @@ Use the [`TrezorWalletController`](https://github.com/flare-foundation/flare-tx-
282302
}
283303
```
284304
305+
:::info[Advanced]
306+
307+
If none of the Wallet controllers listed here meet your needs, you can implement a [custom wallet controller](/network/flare-tx-sdk/advanced-usage#custom-wallets).
308+
309+
:::
310+
285311
## Next steps
286312
287313
- Explore the [Cookbook](/network/flare-tx-sdk/cookbook) for task-oriented guides (balances, transfers, rewards, staking).
288314
- Check the [Advanced Features](/network/flare-tx-sdk/advanced-usage) for transaction callbacks and custom wallets.
315+
- Read the SDK source code on [GitHub](https://github.com/flare-foundation/flare-tx-sdk).

docs/network/flare-tx-sdk/2-cookbook.mdx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ keywords:
1616
tags: [intermediate, javascript]
1717
---
1818

19-
The Cookbook contains ready-to-use code snippets for common operations with the Flare Transaction SDK.
19+
This Cookbook contains ready-to-use code snippets for common operations with the Flare Transaction SDK.
2020

21-
## Get account balances
21+
## Retrieve account balances
2222

2323
The Flare network uses two chains:
2424

@@ -55,6 +55,7 @@ Use `Amount.nats()` or `Amount.wnats()` helpers to convert human-readable values
5555
## Wrap and transfer
5656

5757
Transfer native FLR and its wrapped form (WFLR) on the C-Chain.
58+
Wrapping is required for governance and FTSO delegation, since only WFLR can be delegated.
5859

5960
- **FLR** (native token) lives on both chains.
6061
- **WFLR** (wrapped FLR) exists only on the C-Chain for use in smart contracts and delegation.
@@ -83,7 +84,7 @@ await network.unwrapToNative(wallet, Amount.wnats(1));
8384

8485
:::
8586

86-
## Rewards
87+
## Claim rewards
8788

8889
Flare supports multiple reward sources: FlareDrops, staking rewards, rNat (e.g. rFLR), and FTSO rewards.
8990

@@ -123,8 +124,13 @@ Optional parameters are the same as [FlareDrops](#flaredrops).
123124

124125
rNat tokens (rFLR on Flare) represent vested rewards.
125126
They are backed by WFLR in a dedicated rNat account.
127+
The flow of rFLR:
126128

127-
#### List and claim rewards
129+
```plaintext
130+
rFLR (reward token) → backed by WFLR → claimable → withdraw → optional penalty if locked.
131+
```
132+
133+
#### List and claim
128134

129135
```javascript
130136
// Get a list of all rNat projects
@@ -143,7 +149,7 @@ Claim rewards for one or more projects:
143149
await network.claimRNatReward(wallet, [projectId1, projectId2]);
144150
```
145151

146-
Claimed rewards are deposited as wrapped coins to the rNat account linked to the wallet's C-chain address.
152+
Claimed rewards are deposited as wrapped coins to the rNat account linked to the wallet's C-Chain address.
147153

148154
#### Manage balances
149155

@@ -174,7 +180,7 @@ The returned [`RNatAccountBalance`](https://github.com/flare-foundation/flare-tx
174180
You can also withdraw all funds (locked + unlocked):
175181

176182
```javascript
177-
await network.withdrawAllFromRNatAccount(wallet, wrap);
183+
await network.withdrawAllFromRNatAccount(wallet, /* wrap: boolean */ true);
178184
```
179185

180186
Withdrawing locked balance incurs a **penalty**, so the withdrawn amount will be reduced.
@@ -220,13 +226,14 @@ if (ftsoRewardAmount > 0) {
220226

221227
Optional parameters:
222228

223-
- `rewardOwner` (address) - C-chain address of the reward owner
224-
- `recipient` (address) - C-chain address of where the reward should be transferred
229+
- `rewardOwner` (address) - C-Chain address of the reward owner
230+
- `recipient` (address) - C-Chain address of where the reward should be transferred
225231
- `wrap` (bool) - transfer reward as native (default) or wrapped.
226232

227233
#### Claim with proofs
228234

229235
If a reward isn't initialized, you must provide a Merkle proof available in the [flare-foundation/fsp-rewards](https://github.com/flare-foundation/fsp-rewards/) repository.
236+
As an example for reward epoch 320, see the proofs in [`reward-distribution-data.json`](https://github.com/flare-foundation/fsp-rewards/blob/main/flare/320/reward-distribution-data.json).
230237

231238
```javascript
232239
await network.claimFtsoReward(wallet, rewardOwner, recipient, wrap, proofs);
@@ -304,10 +311,10 @@ The SDK automates these steps.
304311

305312
```javascript
306313
// Transfer 100 FLR from C-Chain to P-Chain
307-
await network.transferToP(wallet, Amount.nats(100););
314+
await network.transferToP(wallet, Amount.nats(100));
308315
```
309316

310-
2. **Delegate on P-chain:** Once funds are on the P-Chain, you can delegate them.
317+
2. **Delegate on P-Chain:** Once funds are on the P-Chain, you can delegate them.
311318

312319
```javascript
313320
const amountToDelegate = Amount.nats(50);
@@ -331,7 +338,7 @@ The SDK automates these steps.
331338
await network.transferToC(wallet);
332339
```
333340

334-
## Voting on governance proposals
341+
## Vote on governance proposals
335342

336343
Governance proposals allow community members to vote on protocol decisions using their voting power (based on WFLR balance and staking).
337344

@@ -364,19 +371,10 @@ A proposal can be voted on only when its `state` is ACTIVE.
364371
// Check if a voter has already voted:
365372
await network.hasCastVoteForFoundationProposal(cAddress, proposalId);
366373

367-
// Cast FOR vote
368-
await network.castVoteForFoundationProposal(
369-
wallet,
370-
proposalId,
371-
FoundationProposalSupport.FOR,
372-
);
374+
const support = FoundationProposalSupport.FOR; // or FoundationProposalSupport.AGAINST
373375

374-
// Cast AGAINST vote
375-
await network.castVoteForFoundationProposal(
376-
wallet,
377-
proposalId,
378-
FoundationProposalSupport.AGAINST,
379-
);
376+
// Cast vote
377+
await network.castVoteForFoundationProposal(wallet, proposalId, support);
380378
```
381379

382380
### Delegate votes
@@ -395,7 +393,7 @@ let delegate = await network.getCurrentGovernanceVoteDelegate(cAddress);
395393

396394
```javascript
397395
// Delegate all vote power to another address:
398-
await network.delegateGovernanceVotePower(wallet, delegate);
396+
await network.delegateGovernanceVotePower(wallet, delegateAddress);
399397

400398
// Remove delegation:
401399
await network.undelegateGovernanceVotePower(wallet);
@@ -416,10 +414,11 @@ const delegate = await network.getVoteDelegateForFoundationProposal(
416414
);
417415
```
418416

419-
Queries may **fail** for older proposals, since historical governance vote data is periodically removed from C-chain storage.
417+
Queries may **fail** for older proposals, since historical governance vote data is periodically removed from C-Chain storage.
420418

421419
:::
422420

423421
## Next steps
424422

425423
- Check the [Advanced Features](/network/flare-tx-sdk/advanced-usage) for transaction callbacks and custom wallets.
424+
- Read the SDK source code on [GitHub](https://github.com/flare-foundation/flare-tx-sdk).

0 commit comments

Comments
 (0)