forked from fuseio/fuse-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update: Dart/Flutter SDK page revamp --------- Co-authored-by: Lior Agnin <[email protected]>
- Loading branch information
Showing
24 changed files
with
583 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
docs/developers/fuse-box/flutter-sdk/10-get-token-details.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
); | ||
``` |
26 changes: 26 additions & 0 deletions
26
docs/developers/fuse-box/flutter-sdk/11-get-smart-wallet-token-balance.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
docs/developers/fuse-box/flutter-sdk/12-get-staking-options.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
docs/developers/fuse-box/flutter-sdk/13-stake-and-unstake.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
docs/developers/fuse-box/flutter-sdk/14-get-staked-tokens.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
docs/developers/fuse-box/flutter-sdk/15-get-token-price.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
docs/developers/fuse-box/flutter-sdk/16-get-token-price-change.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
); | ||
``` |
19 changes: 19 additions & 0 deletions
19
docs/developers/fuse-box/flutter-sdk/17-get-price-change-in-interval.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
); | ||
``` |
18 changes: 18 additions & 0 deletions
18
docs/developers/fuse-box/flutter-sdk/18-get-list-of-supported-tokens.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
docs/developers/fuse-box/flutter-sdk/3-send-single-txn.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
Oops, something went wrong.