{"id":13820276,"url":"https://github.com/xclud/web3dart","last_synced_at":"2025-10-23T08:20:07.702Z","repository":{"id":40344973,"uuid":"460071550","full_name":"xclud/web3dart","owner":"xclud","description":"Ethereum library, written in Dart.","archived":false,"fork":true,"pushed_at":"2025-04-03T20:41:13.000Z","size":496,"stargazers_count":188,"open_issues_count":82,"forks_count":98,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-25T12:54:43.005Z","etag":null,"topics":["blockchain","dart","ethereum","flutter","web3"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/web3dart","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"simolus3/web3dart","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xclud.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-02-16T15:50:59.000Z","updated_at":"2025-04-18T22:50:31.000Z","dependencies_parsed_at":"2023-10-11T22:11:15.300Z","dependency_job_id":"92923d56-233a-4ead-86f3-ae14c6746ffa","html_url":"https://github.com/xclud/web3dart","commit_stats":{"total_commits":221,"total_committers":35,"mean_commits":6.314285714285714,"dds":0.6244343891402715,"last_synced_commit":"9701d8bdbb3b0ad35844d55c5889e6c41781056c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xclud%2Fweb3dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xclud%2Fweb3dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xclud%2Fweb3dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xclud%2Fweb3dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xclud","download_url":"https://codeload.github.com/xclud/web3dart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254488693,"owners_count":22079478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","dart","ethereum","flutter","web3"],"created_at":"2024-08-04T08:01:00.706Z","updated_at":"2025-10-23T08:20:01.963Z","avatar_url":"https://github.com/xclud.png","language":"Dart","funding_links":[],"categories":["Flutter"],"sub_categories":["Flutter SDK / Libraries"],"readme":"[![pub package](https://img.shields.io/pub/v/web3dart)](https://pub.dartlang.org/packages/web3dart)\n[![likes](https://img.shields.io/pub/likes/web3dart)](https://pub.dartlang.org/packages/web3dart/score)\n[![points](https://img.shields.io/pub/points/web3dart)](https://pub.dartlang.org/packages/web3dart/score)\n[![popularity](https://img.shields.io/pub/popularity/web3dart)](https://pub.dartlang.org/packages/web3dart/score)\n[![license](https://img.shields.io/github/license/xclud/web3dart)](https://pub.dartlang.org/packages/web3dart)\n[![stars](https://img.shields.io/github/stars/simolus3/web3dart)](https://github.com/xclud/web3dart/stargazers)\n[![forks](https://img.shields.io/github/forks/simolus3/web3dart)](https://github.com/xclud/web3dart/network/members)\n[![sdk version](https://badgen.net/pub/sdk-version/web3dart)](https://pub.dartlang.org/packages/web3dart)\n\nA dart library that connects to interact with the Ethereum blockchain. It connects\nto an Ethereum node to send transactions, interact with smart contracts and much\nmore!\n\n## Features\n\n- Connect to an Ethereum node with the rpc-api, call common methods\n- Send signed Ethereum transactions\n- Generate private keys, setup new Ethereum addresses\n- Call functions on smart contracts and listen for contract events\n- Code generation based on smart contract ABI for easier interaction\n\n### TODO\n\n- Encode all supported solidity types, although only (u)fixed,\n  which are not commonly used, are not supported at the moment.\n\n## Usage\n\n### Credentials and Wallets\n\nIn order to send transactions on the Ethereum network, some credentials\nare required. The library supports raw private keys and v3 wallet files.\n\n```dart\nimport 'dart:math'; //used for the random number generator\n\nimport 'package:web3dart/web3dart.dart';\n// You can create Credentials from private keys\nCredentials fromHex = EthPrivateKey.fromHex(\"c87509a[...]dc0d3\");\n\n// Or generate a new key randomly\nvar rng = Random.secure();\nCredentials random = EthPrivateKey.createRandom(rng);\n\n// In either way, the library can derive the public key and the address\n// from a private key:\nvar address = credentials.address;\nprint(address.hex);\n```\n\nAnother way to obtain `Credentials` which the library uses to sign\ntransactions is the usage of a wallet file. Wallets store a private\nkey securely and require a password to unlock. The library has experimental\nsupport for version 3 wallets commonly generated by other Ethereum clients:\n\n```dart\nimport 'dart:io';\nimport 'package:web3dart/web3dart.dart';\n\nString content = File(\"wallet.json\").readAsStringSync();\nWallet wallet = Wallet.fromJson(content, \"testpassword\");\n\nCredentials unlocked = wallet.privateKey;\n// You can now use these credentials to sign transactions or messages\n```\n\nYou can also create Wallet files with this library. To do so, you first need\nthe private key you want to encrypt and a desired password. Then, create\nyour wallet with\n\n```dart\nWallet wallet = Wallet.createNew(credentials, \"password\", random);\nprint(wallet.toJson());\n```\n\nYou can also write `wallet.toJson()` into a file which you can later open\nwith [MyEtherWallet](https://www.myetherwallet.com/#view-wallet-info)\n(select Keystore / JSON File) or other Ethereum clients like geth.\n\n#### Custom credentials\n\nIf you want to integrate `web3dart` with other wallet providers, you can implement\n`Credentials` and override the appropriate methods.\n\n### Connecting to an RPC server\n\nThe library won't send signed transactions to miners itself. Instead,\nit relies on an RPC client to do that. You can use a public RPC API like\n[infura](https://infura.io/), setup your own using [geth](https://github.com/ethereum/go-ethereum/wiki/geth)\nor, if you just want to test things out, use a private testnet with\n[truffle](https://www.trufflesuite.com/) and [ganache](https://www.trufflesuite.com/ganache). All these options will give you\nan RPC endpoint to which the library can connect.\n\n```dart\nimport 'package:http/http.dart'; //You can also import the browser version\nimport 'package:web3dart/web3dart.dart';\n\nvar apiUrl = \"http://localhost:7545\"; //Replace with your API\n\nvar httpClient = Client();\nvar ethClient = Web3Client(apiUrl, httpClient);\n\nvar credentials = EthPrivateKey.fromHex(\"0x...\");\nvar address = credentials.address;\n\n// You can now call rpc methods. This one will query the amount of Ether you own\nEtherAmount balance = ethClient.getBalance(address);\nprint(balance.getValueInUnit(EtherUnit.ether));\n```\n\n## Sending transactions\n\nOf course, this library supports creating, signing and sending Ethereum\ntransactions:\n\n```dart\nimport 'package:web3dart/web3dart.dart';\n\n/// [...], you need to specify the url and your client, see example above\nvar ethClient = Web3Client(apiUrl, httpClient);\n\nvar credentials = EthPrivateKey.fromHex(\"0x...\");\n\nawait client.sendTransaction(\n  credentials,\n  Transaction(\n    to: EthereumAddress.fromHex('0xC91...3706'),\n    gasPrice: EtherAmount.inWei(BigInt.one),\n    maxGas: 100000,\n    value: EtherAmount.fromUnitAndValue(EtherUnit.ether, 1),\n  ),\n);\n```\n\nMissing data, like the gas price, the sender and a transaction nonce will be\nobtained from the connected node when not explicitly specified. If you only need\nthe signed transaction but don't intend to send it, you can use\n`client.signTransaction`.\n\n### Smart contracts\n\nThe library can parse the abi of a smart contract and send data to it. It can also\nlisten for events emitted by smart contracts. See [this file](https://github.com/xclud/web3dart/blob/development/example/contracts.dart)\nfor an example.\n\n### Dart Code Generator\n\nBy using [Dart's build system](https://github.com/dart-lang/build/), web3dart can\ngenerate Dart code to easily access smart contracts.\n\nInstall web3dart_builders package\n\n```dart\npub add web3dart_builders --dev\n```\n\nTo use this feature, put a contract abi json somewhere into `lib/`.\nThe filename has to end with `.abi.json`.\nThen, add a `dev_dependency` on the `build_runner` package and run\n\n```dart\npub run build_runner build\n```\n\nYou'll now find a `.g.dart` file containing code to interact with the contract.\n\n#### Optional: Ignore naming suggestions for generated files\n\nIf importing contract ABIs with function names that don't follow dart's naming conventions, the dart analyzer will (by default) be unhappy about it, and show warnings.\nThis can be mitigated by excluding all the generated files from being analyzed.  \nNote that this has the side effect of suppressing serious errors as well, should there exist any. (There shouldn't as these files are automatically generated).\n\nCreate a file named `analysis_options.yaml` in the root directory of your project:\n\n```dart\nanalyzer:\n  exclude: \n    - '**/*.g.dart'\n```\n\nSee [Customizing static analysis](https://dart.dev/guides/language/analysis-options) for advanced options.\n\n## Feature requests and bugs\n\nPlease file feature requests and bugs at the [issue tracker][tracker].\nIf you want to contribute to this library, please submit a Pull Request.\n\n[tracker]: https://github.com/xclud/web3dart/issues/new\n\n## Testing\n\n```dart\ndart test test\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxclud%2Fweb3dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxclud%2Fweb3dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxclud%2Fweb3dart/lists"}