Base
Pronto para usar isso em produção?
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Base
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Web3Dart is the primary library for reaching Base from Dart and Flutter, letting you ship a single cross-platform codebase to iOS, Android, and web that talks to the Coinbase-built L2. Since Base is EVM-equivalent with ETH gas, Web3Dart's standard eth_* calls work as-is against https://base.therpc.io/YOUR_API_KEY. Add it with flutter pub add web3dart for Flutter, or dart pub add web3dart for a pure Dart project. In production, always store private keys in flutter_secure_storage — never hardcode them in source or commit them to a repo.
Web3Dart works in both Flutter and pure Dart projects, so the same Base integration backs a mobile app and a command-line tool. Add it with flutter pub add web3dart. For any production Base app, keep private keys in flutter_secure_storage and never hardcode them.
Create a client by passing your Base endpoint and an http.Client() to Web3Client('https://base.therpc.io/YOUR_API_KEY', Client()). For production transactions, set explicit gas limits rather than relying solely on auto-estimation — estimation can fail or under-quote, and a hardcoded ceiling keeps a transaction from being rejected. Base fees are paid in ETH and are typically low, but always confirm the chain ID is 8453 before broadcasting.
In Flutter, hold the fetched Base balance in a StatefulWidget and call setState to redraw the UI when it changes. Don't fire an RPC call on every build — widgets can rebuild many times per second, and even with Base's fast ~2s blocks a balance barely changes between rebuilds. Cache the last value and refresh on an explicit action or a timer, or debounce the calls, to avoid hammering the endpoint and burning request quota.
To call a contract deployed on Base, build a DeployedContract from the ABI JSON string and the contract's address — you can copy both from https://basescan.org. Use client.call(...) for read-only view functions, which return data without spending gas, and client.sendTransaction(...) for writes that change state and cost ETH for gas. This pattern covers everything from reading an ERC-20 balance to swapping on Aerodrome.
Wrap raw Web3Dart exceptions in a domain-specific EthereumException so your Flutter UI handles one clean error type instead of leaking RPC internals from the Base node. A small EtherAmount extension is also worth adding to turn wei values into trimmed, human-readable ETH strings for display — useful since Base balances are denominated in ETH down to 18 decimals.