Skip to content

Commit

Permalink
Dart/Flutter SDK Page Revamp
Browse files Browse the repository at this point in the history
* update: Dart/Flutter SDK page revamp

---------

Co-authored-by: Lior Agnin <[email protected]>
  • Loading branch information
emmaodia and LiorAgnin authored Feb 6, 2024
1 parent 2023a30 commit 0cb0d64
Show file tree
Hide file tree
Showing 24 changed files with 583 additions and 406 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Installation And Setup
sidebar_position: 2
sidebar_position: 1
---

To get started with the Flutter SDK, add the following dependency to your project's `pubspec.yaml`file:
Expand All @@ -19,7 +19,7 @@ import 'package:fuse_wallet_sdk/fuse_wallet_sdk.dart';

To use the Fuse Flutter SDK in your project, you must create an instance of the **`FuseSDK`** class. This class is the key to interacting with the Fuse API using the SDK. Fortunately, the `FuseSDK` class provides a range of instance methods, allowing you to execute various operations with the API.

Whether you aim to fetch or create a smart wallet, relay an ERC20/FUSE transfer, relay an ERC721 transfer, relay a generic transaction, swap tokens, or stake tokens, the `FuseSDK` class has covered you. Additionally, the SDK provides data features that allow you to get the list of tokens owned by an address, get token details, and get a smart wallet's token balance.
Whether you aim to fetch or create a smart wallet, relay an ERC20/FUSE transfer, relay an ERC721 transfer, relay a generic transaction, swap tokens, or stake tokens, the `FuseSDK` class has you covered. Additionally, the SDK provides data features that allow you to get the list of tokens owned by an address, get token details, and get a smart wallet's token balance.

The following code initializes the Fuse SDK and creates an instance of the `FuseSDK` class. The `publicApiKey` variable should be set to your own API key.

Expand Down
24 changes: 24 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/10-get-token-details.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: GET Token Details
sidebar_position: 10
---

### Get Token Details

The **`getTokenDetails()`** function allows you to retrieve detailed information about a specific ERC20 token. This includes the token's name, symbol, decimal places, and total supply. To use the `getTokenDetails` function, you need to provide the contract address of the ERC20 token that you want to retrieve information from. Once you call the function, it will return a `TokenDetails` object that contains all the relevant information about the token.

```dart
final String tokenAddress = 'TOKEN_ADDRESS';
final tokenDetailsData = await fuseSDK.explorerModule.getTokenDetails(
tokenAddress,
);
tokenDetailsData.pick(
onData: (TokenDetails tokenList) {
// Do you magic here
},
onError: (err) {
// Handle errors
},
);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: GET Smart Wallet Token Balance
sidebar_position: 11
---

### Get Smart Wallet’s Token Balance

The **`getTokenBalance()`** function allows you to retrieve the balance of a specific ERC20 token owned by a Fuse wallet. You will need to provide the contract address of the token and the address of the Fuse wallet. The function returns the balance as a `BigInt` object, which you can use to perform further calculations or display the balance to the user.

```dart
final String tokenAddress = 'TOKEN_ADDRESS';
final String smartWalletAddress = fuseSDK.wallet.getSender();
final tokenBalanceData = await fuseSDK.explorerModule.getTokenBalance(
tokenAddress,
smartWalletAddress,
);
tokenBalanceData.pick(
onData: (BigInt value) {
// Do you magic here
},
onError: (err) {
// Handle errors
},
);
```
18 changes: 18 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/12-get-staking-options.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: GET Staking Options
sidebar_position: 12
---

### Get Staking Options

```dart
final stakingOptionsData = await fuseSDK.stakingModule.getStakingOptions();
stakingOptionsData.pick(
onData: (List<StakingOption> data) {
// Do you magic here
},
onError: (Exception err) {
// Handle errors
}
);
```
40 changes: 40 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/13-stake-and-unstake.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Stake and Unstake Tokens
sidebar_position: 13
---

### Stake

```dart
final res = await fuseSDK.stakeToken(
StakeRequestBody(
accountAddress: fuseSDK.wallet.getSender(),
tokenAmount: 'AMOUNT', // "0.01"
tokenAddress: 'TOKEN_ADDRESS', // "0x34Ef2Cc892a88415e9f02b91BfA9c91fC0bE6bD4"
),
);
print('UserOpHash: ${res.userOpHash}');
print('Waiting for transaction...');
final ev = await res.wait();
print('Transaction hash: ${ev?.transactionHash}');
```

### Unstake

```dart
final res = await fuseSDK.unstakeToken(
UnstakeRequestBody(
accountAddress: fuseSDK.wallet.getSender(),
tokenAmount: '0.1',
tokenAddress: 'TOKEN_ADDRESS', // "0x34Ef2Cc892a88415e9f02b91BfA9c91fC0bE6bD4"
),
EthereumAddress.fromHex('0xb1DD0B683d9A56525cC096fbF5eec6E60FE79871'),
);
print('UserOpHash: ${res.userOpHash}');
print('Waiting for transaction...');
final ev = await res.wait();
print('Transaction hash: ${ev?.transactionHash}');
```
20 changes: 20 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/14-get-staked-tokens.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: GET Staked Tokens
sidebar_position: 14
---

### Get Staked Tokens

```dart
final smartWalletAddress = fuseSDK.wallet.getSender();
final stakedTokensData = await fuseSDK.stakingModule.getStakedTokens(smartWalletAddress);
stakedTokensData.pick(
onData: (StakedTokenResponse data) {
// Do you magic here
},
onError: (err) {
// Handle errors
}
);
```
19 changes: 19 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/15-get-token-price.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: GET Token Price
sidebar_position: 15
---

### Get Token Price

```dart
final tokenAddress = 'TOKEN_ADDRESS';
final priceData = await fuseSDK.tradeModule.price(tokenAddress);
priceData.pick(
onData: (String tokenPrice) {
// Do you magic here
},
onError: (err) {
// Handle errors
},
);
```
19 changes: 19 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/16-get-token-price-change.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: GET Token Price Change in the Last 24 hours
sidebar_position: 16
---

### Get Token Price Change in the last 24 hours

```dart
final tokenAddress = 'TOKEN_ADDRESS';
final priceChangeData = await fuseSDK.tradeModule.priceChange(tokenAddress);
priceChangeData.pick(
onData: (String priceInfo) {
// Do you magic here
},
onError: (err) {
// Handle errors
},
);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: GET the Price Change in Interval
sidebar_position: 17
---

### Get Price Change in Interval

```dart
final tokenAddress = 'TOKEN_ADDRESS';
final intervalData = await fuseSDK.tradeModule.interval(tokenAddress, TimeFrame.day);
intervalData.pick(
onData: (List<IntervalStats> stats) {
// Do you magic here
},
onError: (err) {
// Handle errors
},
);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: GET the list of Supported Tokens
sidebar_position: 18
---

### Get the list of Supported Tokens

```dart
final tokensData = await fuseSDK.tradeModule.fetchTokens();
tokensData.pick(
onData: (List<TokenDetails> tokens) {
// Do you magic here
},
onError: (err) {
// Handle errors
},
);
```
17 changes: 17 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/19-sponsored-txn.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Sponsored Transactions
sidebar_position: 19
---

### Sponsored Transactions

Sponsored transactions are the ability to pay for another user’s transaction fees. To do this, the Fuse operator must enable the sponsored feature in his project and deposit some funds into the paymaster contract. The SDK provides a middleware to check if the project is sponsored and the amount of funds available for sponsoring.

To use this feature, you must first initialize the SDK with the `withPaymaster` parameter set to `true`.

```dart
import 'package:fuse_wallet_sdk/fuse_wallet_sdk.dart';
final apiKey = 'YOUR_PUBLIC_API_KEY';
final privateKey = EthPrivateKey.fromHex('YOUR_PRIVATE_KEY');
final fuseSDK = await FuseSDK.init(apiKey, privateKey, withPaymaster: true);
```
31 changes: 31 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/2-create-scw.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Create Smart Contract Wallet
sidebar_position: 2
---

### Initialization

The `init` method is a fundamental feature of the Fuse Wallet Flutter SDK that enables you to setup a wallet & authenticate the user's provided credentials. The method requires the use of a `PRIVATE_KEY` which you can get in the Fuse Developer Console [here](https://developers.fuse.io/). When you send a request to the server using this method, it verifies the credentials and if the credentials are valid, developers can use the **`getSender()`** to return an address.

```dart
//Enter your Fuse Developer API Key
final publicApiKey = 'YOUR_API_KEY';
// Generate a random Ethereum private key
final String privateKey = await Mnemonic.generatePrivateKey();
final EthPrivateKey credentials = EthPrivateKey.fromHex(privateKey);
final fuseSDK = await FuseSDK.init(credentials);
```

### **Access the wallet**

```dart
// Create Wallet
final smartContractAddress = fuseSDK.wallet.getSender();
print('Smart contract wallet address: $smartContractAddress');
```

## Code example

For more code examples on using the Fuse Wallet SDK for Creating Address using Flutter, you can check out the official [**Flutter SDK repository**](https://github.com/fuseio/fuse_wallet_sdk/blob/master/example/address.dart).
31 changes: 31 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/3-send-single-txn.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Send Native/ERC20 Transactions
sidebar_position: 3
---

### Transfer ERC20 Token/ Native FUSE

To transfer an ERC20/FUSE with a relay, use the **`transferToken()`** method. This method relays the transaction and covers the gas fees for the user, so they don't need to worry about those fees.

You can also subscribe to events related to the token transfer to track its progress. The method takes the following parameters as inputs:

| Parameter | Type | Description |
| ---------------- | --------- | ----------------------------------------------- |
| tokenAddress | _address_ | The contract address of the ERC20 token or FUSE |
| recipientAddress | _address_ | The recipient's wallet address |
| amount | _number_ | The amount to transfer |

```dart
final res = await fuseSDK.transferToken(
EthereumAddress.fromHex('TOKEN_ADDRESS'), // For sending native token, use '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
EthereumAddress.fromHex('RECIPIENT_ADDRESS'),
BigInt.parse('AMOUNT_IN_WEI'),
);
print('UserOpHash: ${res.userOpHash}');
print('Waiting for transaction...');
final ev = await res.wait();
```

## Code example

For more code examples on using the Fuse Wallet SDK for Flutter for Token Transfer, you can check out the official [**Flutter SDK repository**](https://github.com/fuseio/fuse_wallet_sdk/blob/master/example/transfer.dart).
61 changes: 61 additions & 0 deletions docs/developers/fuse-box/flutter-sdk/4-send-batch-txn.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: Send Batch Transactions
sidebar_position: 4
---

### Batch Transactions

A batch refers to a group of calls inside a single user operation. This can be an approve and send transaction in one call. The executeBatch() method is used.

The executeBatch() method takes in an array of _`Call()`_. With each method taking in 3 keys: to, value and data.

```dart
executeBatch([
Call(to: to, value: value, data: data),
Call(to: to, value: value, data: data),
Call(to: to, value: value, data: data),
]);
```

| Parameter | Type | Status | Description |
| :-------: | ---------- | ---------- | ------------------------------------------------ |
| **to** | _address_ | _required_ | The address where the user want to send Tokens. |
| **value** | _number_ | _required_ | The amount of Tokens the user is sending |
| **data** | _Function_ | | Encoded Function Data for Smart Contract Methods |

Example **`approve_and_transfer.dart`**

```dart
final tokenAddress = EthereumAddress.fromHex('TOKEN_ADDRESS');
final recipientAddress = EthereumAddress.fromHex('RECIPIENT_ADDRESS');
final amountInWei = BigInt.parse('AMOUNT_IN_WEI');
final res = await fuseSDK.executeBatch(
[
// Approve ERC20 Token call
Call(
to: tokenAddress,
value: BigInt.zero,
data: ContractsUtils.encodeERC20ApproveCall(
tokenAddress,
recipientAddress,
amountInWei,
),
),
// Transfer ERC20 Token call
Call(
to: tokenAddress,
value: BigInt.zero,
data: ContractsUtils.encodeERC20TransferCall(
tokenAddress,
recipientAddress,
amountInWei,
),
),
],
);
```

## Code example

For more code examples on using the Fuse Wallet SDK for Flutter for Batch Transfer, you can check out the official [**Flutter SDK repository**](https://github.com/fuseio/fuse_wallet_sdk/blob/master/example/batch_transactions.dart).
Loading

0 comments on commit 0cb0d64

Please sign in to comment.