搜索插件、代码仓与 APP 分类

插件详情v0.3.8

fuse_wallet_sdk

Fuse Wallet SDK 现在提供了 Dart 实现,使您能够更轻松地将区块链技术集成到移动应用中。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
383
喜欢数
9
Pub 分数
125

安装插件

flutter pub add fuse_wallet_sdk

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Fuse Wallet SDK 提供了 Dart 实现,用于将区块链功能集成到移动和桌面应用程序中。它可在 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台上实现无缝的钱包管理、交易处理和区块链交互。专为开发 Web3 应用程序的开发者设计,通过安全且易于使用的 API 简化用户接入区块链生态系统的流程。该 SDK 支持与 Fuse 网络的互操作性,并通过原生区块链功能增强应用程序能力。

适合场景

  • 将区块链钱包集成到Flutter应用中
  • 在Fuse网络上启用用户账户创建
  • 促进代币转账和交易
  • 支持去中心化应用(dApp)身份验证
  • 构建跨平台的Web3体验

主要特点

  • 跨平台兼容性
  • 安全的钱包管理
  • 原生 Dart 集成
  • 对 Fuse 网络的支持
  • 通过 Flutter Pub 实现轻松设置

适合对象

  • Flutter 开发人员构建 dApps
  • Web3 初创企业
  • 基于区块链的移动应用
  • 加密钱包集成
  • 多平台区块链项目

使用建议

  • 需要理解区块链基础知识
  • 取决于Fuse网络的可用性
  • 可能需要额外的安全审计
  • 仅限Fuse生态系统
  • 需要对私钥进行正确处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

MIT License pub version

Introduction

The Fuse Wallet SDK is a set of tools for creating, managing, and engaging with Fuse Wallet SDK in client applications. Fuse Wallet SDK lets users create smart contract wallets(Based on ERC-4337) associated with each user's Externally Owned Account (EOA) that provide added security compared to traditional EOAs with a single private key. With Fuse Wallet SDK, users can deposit funds that no one else can control and withdraw at any time.

Benefits of using Fuse Wallet SDK

Using Fuse Wallet SDK provides several benefits, including:

  • Enhanced security: Fuse Wallet SDK are non-custodial accounts that allow users to deposit funds that no one else can control and withdraw at any time. Each Fuse Smart Wallet is a smart contract associated with the user's EOA and can only be controlled by that user.
  • Enhanced UX: Fuse Wallet SDK support gasless transactions, improving the user experience and making it more seamless to interact with the blockchain.
  • Better developer experience: The Fuse Wallet SDK abstracts away the complexities of web3 development, such as cryptography, wallet management, and smart contract interactions, making it easier for developers to build blockchain-based applications
Purpose of the SDK

The SDK is designed to make it easy for developers to create, manage, and engage with Fuse Wallet SDK in their applications. The SDK provides pre-built functions and utilities, allowing developers to interact with Fuse Wallet SDK securely and efficiently.

Migration guides

Instantiation

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);
Examples
Get Address
Send transactions
Approve token
Retry mechanism
Send batch transactions
Staking
Unstake
Trading

Features

The Fuse Wallet SDK provides several features that allow developers to create, manage, and engage with Fuse Wallet SDK in their applications. Some of the key features include:

Get Address

Gets the address of the wallet created.

print('Smart contract wallet address: ${fuseSDK.wallet.getSender()}');
Send transactions

Send transactions, including ERC20 and NFT transfers and interaction with arbitrary smart contracts.

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();
Send batch transactions

The process of grouping multiple transactions into a single batch to be processed together. This is often done to optimize processing time and reduce transaction fees.

final res = await fuseSDK.executeBatch(
  [
    // Transfer Native Token call
    Call(
      to: EthereumAddress.fromHex('TARGET_ADDRESS'),
      value: BigInt.parse('AMOUNT_IN_WEI'),
      data: Uint8List(0),
    ),
    // Transfer ERC-20 Token call
    Call(
      to: EthereumAddress.fromHex('TOKEN_ADDRESS'),
      value: BigInt.zero,
      data: ContractsUtils.encodeERC20TransferCall(
        EthereumAddress.fromHex('TOKEN_ADDRESS'),
        EthereumAddress.fromHex('RECIPIENT_ADDRESS'),
        BigInt.parse('AMOUNT_IN_WEI'),
      ),
    ),
  ],
);

print('UserOpHash: ${res.userOpHash}');

print('Waiting for transaction...');
final ev = await res.wait();
print('Transaction hash: ${ev?.transactionHash}');
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.

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);
Staking

The SDK provides a module for staking. This module allows users to stake their tokens and earn rewards.

Currently, the SDK supports staking for the following tokens: Native Fuse & VoltToken


final stakingOptions = await fuseSDK.stakingModule.getStakingOptions();

final res = await fuseSDK.stakeToken(
  StakeRequestBody(
    accountAddress: fuseSDK.wallet.getSender(),
    tokenAmount: '0.1',
    tokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  ),
);
Trading

Smart Wallet can buy and sell popular cryptocurrencies like Bitcoin and Ethereum, Stable-coins. Behind the scenes, it uses voltage.finance decentralized exchange.

final nativeTokenAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
final usdcTokenAddress = '0x28C3d1cD466Ba22f6cae51b1a4692a831696391A';

final res = await fuseSDK.swapTokens(
  TradeRequest(
    inputToken: nativeTokenAddress,
    outputToken: usdcTokenAddress,
    inputAmount: BigInt.parse('100000000000000000'),
    exactIn: true,
  ),
);

Troubleshooting

  1. User op cannot be replaced: fee too low.

    If you're getting the User op cannot be replaced: fee too low error, it means that the gas price you set is too low. You can increase the gas price by setting the TxOptions parameter when sending a transaction. To replace an user operation, a new user operation must have at least 10% higher maxPriorityFeePerGas and 10% higher maxPriorityFeePerGas than the one in the user operation mempool.

To replace the user operation, the new gas price must be at least 10% higher.

final res = await fuseSDK.transferToken(
    EthereumAddress.fromHex('TOKEN_ADDRESS'),
    EthereumAddress.fromHex('RECIPIENT_ADDRESS'),
    BigInt.parse('AMOUNT_IN_WEI'),
    FuseSDK.defaultTxOptions.copyWith(
      withRetry: true,
      feeIncrementPercentage: 11,
    ),
);
print('UserOpHash: ${res.userOpHash}');
print('Waiting for transaction...');
final ev = await res.wait();

Limitations

The Fuse Wallet SDK works only on the Fuse & Fuse Sparknet networks, an EVM based chain L1 blockchain. Support for other blockchains is planned for the future.

If you have any questions or feedback, please get in touch with our support team at support@fuse.io.

Migrating to v0.2

Introduction

Welcome to the updated version of the fuse_wallet_sdk. Our primary objective for this migration is to seamlessly align our services with the evolving landscape of EVM-based chains. We are thrilled to introduce the incorporation of the new standard, EIP 4337, commonly known as "Account Abstraction". This latest protocol promises to enhance security, provide more consistent developer experiences, and offer improved user interactions in Ethereum-based environments.

Major Changes at a Glance:

  • Seamless Smart Wallet Creation: Gone are the days where we required an API request to the Fuse APIs to craft a smart wallet. With the renewed fuse_wallet_sdk, initiation not only sets the SDK in motion but also seamlessly creates a smart wallet for the given owner. This elevates user experience, reduces developer friction, and augments transactional efficiency.

As we navigate through the details of this migration, we hope to provide you with a clear roadmap, making the transition as straightforward as possible. Embracing the future of Ethereum-based chains has never been this effortless.

Prerequisites

Before embarking on this migration journey with the new fuse_wallet_sdk, the process is made delightfully simple for our users. However, there's a minimal requirement you should be aware of:

  • API Key: The only prerequisite to utilize the updated SDK is to have a valid API key. If you haven't create one yet or need a new one, don't fret! Simply head over to our Developer's Console at https://console.fuse.io/build/ and follow the straightforward steps to obtain your key.

With your API key in hand, you're all set to integrate and experience the enhanced capabilities of the fuse_wallet_sdk.

Detailed Migration Steps

Initialization and Smart Wallet Creation

  1. Locate the Old Initialization: Start by finding your old SDK initialization in your code. This is typically where you have the FuseWalletSDK instantiation.

  2. Remove Wallet Creation Steps: In the old SDK, there were multiple steps involved in creating a smart wallet, including authenticating the credentials, creating a wallet, and handling the creation events. These steps are now greatly simplified in the new SDK.

    Identify and remove the following sections from your old SDK code:

    • The authentication step: await fuseWalletSDK.authenticate(credentials);
    • The wallet creation step: await fuseWalletSDK.createWallet();
    • The entire onSmartWalletEvent function and its associated event listening code.
  3. Update SDK Initialization: Replace the old initialization:

    final FuseWalletSDK fuseWalletSDK = FuseWalletSDK(publicApiKey);
    

    with the new one:

    final fuseSDK = await FuseSDK.init(publicApiKey, credentials);
    
  4. Access the Smart Contract Wallet Address: In the new SDK, you can obtain the smart contract wallet address directly after initialization. Replace the older method:

    print('Smart contract wallet address: ${fuseWalletSDK.smartWallet.smartWalletAddress}');
    

    with the simplified new version:

    print('Smart contract wallet address: ${fuseSDK.wallet.getSender()}');
    
    

By following the steps above, developers can smoothly transition to the new SDK and take advantage of the more streamlined and simplified process provided by the update. It’s worth noting that the migration not only reduces the lines of code but also enhances clarity and reduces complexity, resulting in a more efficient and cleaner integration process.

In summary, the new SDK code provides a more structured, modular, and extensive set of functions to interact with FuseBox. It allows for a broader range of operations, from basic token transfers to more complex operations like staking and swapping tokens. The design considerations (like separating modules) make the SDK more maintainable and scalable.

所属分类

依赖

依赖清单 14 项

源码仓库

使用此插件的项目

暂无相关数据。