Skip to content

Commit d4e29b9

Browse files
committed
fix(docs): improve code examples
1 parent 9104d3b commit d4e29b9

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ description: Software Development Kit for performing common operations on Flare.
55
keywords: [sdk, flare-network, developer tools]
66
---
77

8+
import Tabs from "@theme/Tabs";
9+
import TabItem from "@theme/TabItem";
10+
811
Flare Transaction SDK ([`@flarenetwork/flare-tx-sdk`](https://www.npmjs.com/package/@flarenetwork/flare-tx-sdk/)) is the official Node.js Software Development Kit for performing common actions on Flare's networks:
912

1013
- Retrieving account and balance information
@@ -33,9 +36,23 @@ Before you start, ensure you have the following:
3336

3437
To get started, install the SDK into your Node.js project:
3538

36-
```bash
37-
npm install @flarenetwork/flare-tx-sdk
38-
```
39+
<Tabs>
40+
<TabItem value="npm" label="npm" default>
41+
42+
```bash
43+
npm install @flarenetwork/flare-tx-sdk
44+
```
45+
46+
</TabItem>
47+
<TabItem value="yarn" label="yarn">
48+
49+
```bash
50+
yarn add @flarenetwork/flare-tx-sdk
51+
```
52+
53+
</TabItem>
54+
55+
</Tabs>
3956

4057
## Core concepts
4158

@@ -77,18 +94,11 @@ async function main() {
7794
console.log("Fetching balance...");
7895
const balance = await network.getBalance(publicKey);
7996
console.log("✅ Balance retrieved successfully!");
80-
8197
// All amounts are returned as wei
8298
console.log(` - Available on C-Chain: ${balance.availableOnC} wei`);
8399
console.log(` - Wrapped on C-Chain: ${balance.wrappedOnC} wei`);
84100
console.log(` - Available on P-Chain: ${balance.availableOnP} wei`);
85101
console.log(` - Staked on P-Chain: ${balance.stakedOnP} wei`);
86-
console.log(
87-
` - Not yet imported to C-Chain: ${balance.notImportedToC} wei`,
88-
);
89-
console.log(
90-
` - Not yet imported to P-Chain: ${balance.notImportedToP} wei`,
91-
);
92102
}
93103

94104
main().catch(console.error);
@@ -202,7 +212,7 @@ You can also pass additional parameters to modify:
202212
await network.claimFtsoReward(wallet, rewardOwner, recipient, wrap);
203213
```
204214

205-
#### Detailed reward overview
215+
#### Detailed rewards
206216

207217
```javascript
208218
let states = await network.getStateOfFtsoRewards(cAddress);
@@ -217,6 +227,8 @@ It can be empty or it consists of objects of type [`FtsoRewardState`](https://gi
217227
- `claimType` (string) - The type of claim (`DIRECT`, `FEE`, `WNAT`, `MIRROR`, or `CCHAIN`).
218228
- `initialised` (boolean) - flag indicating if the reward can be claimed without providing proofs.
219229

230+
#### Claim with proofs
231+
220232
Rewards that are not initialized can be claimed using Merkle proofs available in the [flare-foundation/fsp-rewards](https://github.com/flare-foundation/fsp-rewards/) repository.
221233

222234
```javascript
@@ -329,15 +341,9 @@ The SDK streamlines this cross-chain process.
329341

330342
## Wallet controllers
331343

332-
To sign transactions, you must provide an object that implements the [`Wallet`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/index.ts) interface.
344+
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 [`Wallet`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/index.ts) objects.
333345
The SDK includes controllers for popular wallet standards to make this easy.
334346

335-
:::tip[What is a Wallet Controller?]
336-
337-
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 `Wallet` objects.
338-
339-
:::
340-
341347
### EIP-1193 Wallets
342348

343349
Use the [`EIP1193WalletController`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/eip1193/controller.ts) for any browser-based wallet that exposes an EIP-1193 provider (`window.ethereum`) such as MetaMask or WalletConnect.
@@ -360,15 +366,15 @@ controller.onWalletChange((newWallet) => {
360366

361367
### Ledger
362368

363-
Use the [`LedgerWalletController`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/ledger/controller.ts) with the [@zondax/ledger-flare](https://www.npmjs.com/package/@zondax/ledger-flare) or [@ledgerHQ/hw-app-eth](https://www.npmjs.com/package/@ledgerhq/hw-app-eth) libraries to sign with a Ledger device.
369+
Use the [`LedgerWalletController`](https://github.com/flare-foundation/flare-tx-sdk/blob/HEAD/src/wallet/ledger/controller.ts) with either [`@zondax/ledger-flare`](https://www.npmjs.com/package/@zondax/ledger-flare) or [`@ledgerHQ/hw-app-eth`](https://www.npmjs.com/package/@ledgerhq/hw-app-eth) libraries to sign with a Ledger device.
364370

365371
```javascript
366372
import { LedgerWalletController } from "@flarenetwork/flare-tx-sdk";
367373

368374
// Option 1: Setup with Zondax
369-
// import { FlareApp } from "@zondax/ledger-flare"
370-
// flrApp = FlareApp(...)
371-
// const controller = new LedgerWalletController(flrApp, null);
375+
import { FlareApp } from "@zondax/ledger-flare"
376+
flrApp = FlareApp(...)
377+
const controller = new LedgerWalletController(flrApp, null);
372378

373379
// Option 2: Setup with LedgerHQ
374380
// import { Eth } from "@ledgerHQ/hw-app-eth"
@@ -398,7 +404,8 @@ const wallet = await controller.getWallet("m/44'/60'/0'/0/0");
398404

399405
### Transaction tracking
400406

401-
For fine-grained control and monitoring, you can register callbacks that fire at different stages of a transaction's lifecycle.
407+
For fine-grained control and monitoring, you can register [callbacks](https://github.com/flare-foundation/flare-tx-sdk/blob/main/src/network/callback.ts) that fire at different stages of a transaction's lifecycle.
408+
All
402409
This is useful for UI updates, logging, or offline signing workflows.
403410

404411
```javascript
@@ -409,6 +416,7 @@ This is useful for UI updates, logging, or offline signing workflows.
409416
// Returning `false` will cancel the signing request.
410417
network.setBeforeTxSignatureCallback(async (data) => {
411418
console.log("Transaction to be signed:", data.unsignedTxHex);
419+
console.log("Transaction ID:", data.txType); // https://github.com/flare-foundation/flare-tx-sdk/blob/main/src/network/txtype.ts
412420
return true; // Allow signing
413421
});
414422

@@ -417,19 +425,21 @@ network.setBeforeTxSignatureCallback(async (data) => {
417425
network.setBeforeTxSubmissionCallback(async (data) => {
418426
console.log("Transaction to be submitted:", data.signedTxHex);
419427
console.log("Transaction ID:", data.txId);
428+
console.log("Transaction type:", data.txType); // https://github.com/flare-foundation/flare-tx-sdk/blob/main/src/network/txtype.ts
420429
return true; // Allow submission
421430
});
422431

423432
// 3. After Submission: Get the transaction ID immediately after sending.
424433
network.setAfterTxSubmissionCallback(async (data) => {
425434
console.log(`Transaction ${data.txId} submitted. Awaiting confirmation...`);
435+
console.log("Transaction type:", data.txType); // https://github.com/flare-foundation/flare-tx-sdk/blob/main/src/network/txtype.ts
426436
return true; // Wait for confirmation
427437
});
428438

429439
// 4. After Confirmation: Get the final status of the transaction.
430440
network.setAfterTxConfirmationCallback(async (data) => {
431441
console.log(
432-
`Transaction ${data.txId} confirmed with status: ${data.txStatus ? "Success" : "Failure"}`,
442+
`Transaction ${data.txId} confirmed with status: ${data.txStatus}`,
433443
);
434444
});
435445
```

0 commit comments

Comments
 (0)