Skip to content

A comprehensive, pure Dart Web3 SDK. Supports EVM, Solana, Bitcoin, & more. Features: AA (ERC-4337), WalletConnect, Hardware Wallets.

Notifications You must be signed in to change notification settings

ImL1s/dart_web3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

193 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dart Web3 SDK

A comprehensive, pure Dart Web3 SDK for EVM-compatible blockchains and multi-chain support.

Features

  • Pure Dart Implementation - No native dependencies (FFI, C++, Rust bindings), works on all Dart/Flutter platforms
  • Modular Architecture - Import only what you need, each package is independently usable
  • Multi-Chain Support - Core EVM support with extensions for Solana, Polkadot, Tron, TON, and Bitcoin
  • Hardware Wallets - Built-in support for Ledger, Trezor, Keystone, and various MPC solutions
  • Type-Safe - Leverages Dart's type system for compile-time error checking
  • Modern Standards - Supports EIP-1559, EIP-4844 (Blob), EIP-7702, ERC-4337 (Account Abstraction)

Installation

Add the packages you need to your pubspec.yaml:

dependencies:
  # Core functionality
  dart_web3_core: ^0.1.0
  dart_web3_crypto: ^0.1.0
  dart_web3_abi: ^0.1.0
  
  # Client and provider
  dart_web3_provider: ^0.1.0
  dart_web3_client: ^0.1.0
  
  # Or use the meta-package for everything
  dart_web3: ^0.1.0

Usage Workflow

graph LR
    A[Setup] --> B[Core Components]
    B --> C[Connect & Sign]
    C --> D[Interact]
    D --> E[Advanced Features]

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style C fill:#bfb,stroke:#333,stroke-width:2px
    style D fill:#fbf,stroke:#333,stroke-width:2px
    style E fill:#fbb,stroke:#333,stroke-width:2px
Loading

Quick Start

1. Basic RPC Operations

import 'package:dart_web3/dart_web3.dart';

void main() async {
  final client = ClientFactory.createPublicClient(
    rpcUrl: 'https://eth.llamarpc.com',
    chain: Chains.ethereum,
  );
  
  final blockNumber = await client.getBlockNumber();
  print('Current Block: $blockNumber');
}

2. Contract Interaction (ERC-20)

import 'package:dart_web3/dart_web3.dart';

void main() async {
  final client = ClientFactory.createPublicClient(rpcUrl: '...');
  final contract = ERC20(address: '0x...', client: client);

  final symbol = await contract.symbol();
  final balance = await contract.balanceOf('0x...');
  print('$symbol Balance: ${EthUnit.formatEther(balance)}');
}

3. Batch Calls (Multicall)

import 'package:dart_web3/dart_web3.dart';

void main() async {
  final client = ClientFactory.createPublicClient(rpcUrl: '...');
  final multicall = Multicall(client: client);

  final results = await multicall.aggregate([
    contract.getBalanceRequest('0xUser1'),
    contract.getBalanceRequest('0xUser2'),
    client.getEthBalanceRequest('0xUser1'),
  ]);
}

4. Account Abstraction (ERC-4337)

import 'package:dart_web3/dart_web3.dart';

void main() async {
  final signer = PrivateKeySigner.fromHex('0x...');
  final smartAccount = await SimpleSmartAccount.create(
    signer: signer,
    rpcUrl: '...',
    entryPoint: '0x...',
  );

  final txHash = await smartAccount.sendTransaction(
    to: '0x...',
    value: EthUnit.ether('0.01'),
  );
}

5. Multi-Chain Extensions

import 'package:dart_web3/dart_web3.dart';
import 'package:dart_web3_solana/dart_web3_solana.dart';

void main() async {
  // Use Ethereum core for EVM
  final evmBalance = await evmClient.getBalance('0x...');

  // Use Solana extension for non-EVM
  final solClient = SolanaClient(endpoint: '...');
  final solBalance = await solClient.getBalance('...');
}

Examples

We provide a variety of examples to help you get started with the SDK:

Example Description
Connectivity Check connectivity across multiple networks
Wallet Management HD Wallet derivation, mnemonic generation, and signing
Token Interactions Reading ERC-20 metadata and balances
Account Abstraction ERC-4337 Smart Account setup and UserOps

Find more details in the Usage Guide.

Architecture Blueprint

graph TD
    subgraph L0 [Layer 0: Core Primitives]
        Core[dart_web3_core]
    end

    subgraph L1 [Layer 1: Cryptography & Encoding]
        Crypto[dart_web3_crypto]
        ABI[dart_web3_abi]
    end

    subgraph L2 [Layer 2: Connectivity & Identity]
        Provider[dart_web3_provider]
        Signer[dart_web3_signer]
        Chains[dart_web3_chains]
    end

    subgraph L3 [Layer 3: Client & Interaction]
        Client[dart_web3_client]
        Contract[dart_web3_contract]
    end

    subgraph L4 [Layer 4: Advanced Features]
        ENS[dart_web3_ens]
        AA[dart_web3_aa]
        NFT[dart_web3_nft]
        Swap[dart_web3_swap]
    end

    subgraph Ext [Extensions & Hardware]
        Solana[dart_web3_solana]
        Bitcoin[dart_web3_bitcoin]
        Ledger[dart_web3_ledger]
    end

    Core --> Crypto
    Crypto --> ABI
    ABI --> Provider
    Provider --> Client
    Signer --> Client
    Chains --> Client
    Client --> Contract
    
    Client -.-> ENS
    Client -.-> AA
    Client -.-> NFT
    
    L2 --- Ext
Loading

Package Structure

📦 Modules & Capabilities

The SDK is divided into specialized layers. Click on a package to see its dedicated documentation.

Layer 0-1: Foundation (The "Trust Wallet Core" equivalent)

Low-level primitives for cryptography, encoding, and data models.

  • dart_web3_core: Essential types (EthAddress, BigInt units), RLP encoding, and byte manipulation.
  • dart_web3_crypto: Security-first crypto engine. secp256k1, BIP-39 mnemonics, BIP-44 HD Wallets, and Keccak hashing.
  • dart_web3_abi: Robust ABI v2 codec for encoding/decoding Solidity types, functions, and events.

Layer 2: Connectivity & Identity

Standardized interfaces for connecting to blockchains and managing identities.

  • dart_web3_provider: JSON-RPC 2.0 gateway supporting HTTP and WebSockets with middleware support.
  • dart_web3_signer: Universal signing abstraction for Private Keys, Passkeys, and Hardware Wallets (Ledger/Trezor).
  • dart_web3_chains: Comprehensive registry of EVM networks (metadata, RPCs, contract addresses).

Layer 3: Interaction

The primary developer surface for building DApps.

  • dart_web3_client: High-level PublicClient and WalletClient for composable blockchain interaction.
  • dart_web3_contract: Type-safe wrapper for smart contracts (read state, write transactions, watch events).
  • dart_web3_events: Recursive event filter polling and WebSocket subscription management.

Layer 4-5: Advanced Features

Specialized modules for complex Web3 workflows.

Layer 6: Hardware Security

Air-gapped and secure-element integration.

Layer 7: Multi-Chain Extensions

Beyond the EVM. Native support for other major blockchains.

Development

This project uses Melos for monorepo management.

# Install melos globally
dart pub global activate melos

# Bootstrap the workspace
melos bootstrap

# Run tests
melos test

# Run analysis
melos analyze

License

MIT License - see LICENSE for details.

References

This SDK is inspired by and references:

About

A comprehensive, pure Dart Web3 SDK. Supports EVM, Solana, Bitcoin, & more. Features: AA (ERC-4337), WalletConnect, Hardware Wallets.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •