Polygon
Prêt à utiliser cela en production ?
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
Polygon
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
Web3Dart is the primary library for talking to Polygon from Dart and Flutter, letting you ship a single codebase that runs as a cross-platform mobile and web dApp on iOS, Android, and the browser. Polygon PoS is EVM-equivalent, so Web3Dart's standard Ethereum interface works as-is against https://polygon.therpc.io/YOUR_API_KEY. Add it with flutter pub add web3dart in a Flutter project, or dart pub add web3dart for pure Dart. In production apps, always store private keys in flutter_secure_storage — never hardcode keys in source, where they would ship inside your app bundle for anyone to extract.
Web3Dart works in both Flutter and pure Dart projects, so the same Polygon logic can back a mobile app and a command-line tool. Add it with flutter pub add web3dart. For production, manage private keys with flutter_secure_storage and never hardcode keys — a leaked key on Polygon means an attacker can drain the wallet's MATIC and tokens.
Create a Web3Client by passing the Polygon HTTP endpoint https://polygon.therpc.io/YOUR_API_KEY together with an http.Client() instance, and keep one client alive for the lifetime of your service rather than recreating it per call. For production transactions, set explicit gas limits instead of relying purely on auto-estimation — Polygon gas prices can spike during congestion, and a failed estimate can cause a transaction to be rejected or stuck.
In Flutter, drive the UI with a StatefulWidget and call setState once a fresh balance arrives from Polygon so the widget rebuilds with the new MATIC value. Be careful not to fire an RPC call on every build() — widgets rebuild often — so cache the last result or debounce refreshes behind an explicit user action or a timer to avoid hammering the endpoint.
To interact with a deployed Polygon contract, build a DeployedContract from the contract's ABI JSON string and its on-chain address (chain ID 137). Read-only view functions go through client.call(), which returns decoded values without spending gas, while state-changing functions go through client.sendTransaction() with signing credentials, which submits a transaction and costs MATIC.
Wrap the raw exceptions Web3Dart throws on failed Polygon calls in your own domain-specific EthereumException, so the rest of your app catches one clear error type instead of leaking transport details into the UI layer. Pairing that with an EtherAmount extension that formats balances into trimmed, fixed-decimal display strings keeps MATIC values readable in widgets without scattering conversion logic everywhere.