web3dart 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 42

web3dart #

A library for making transactions in Ethereum using Dart. This library is in early development, has not been through a security audit and should not be used in a productive environment.

Features #

  • Send valid and signed transactions to an Ethereum client using the JSON-RPC API.
  • Generate private keys and Ethereum accounts
  • (sort of) Send messages and function calls to smart contracts


  • Code generation based on smart contract ABI for easier interaction
  • Smart Contract events
  • Encode all supported solidity types

Usage #

In order to use this library, you will need an client connected to Ethereum nodes so that your transactions can actually be processed. You can either set up a local, private blockchain (by for instance using truffle and ganache), run an Ethereum node yourself (for instance with geth), or use a public RPC API, like infura.

import 'package:http/http.dart'; //You can also import the browser version
import 'package:web3dart/web3dart.dart';

main() {
    //Replace with private key of an account that can transfer ether
    var privateKeyHex = "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3";
    var apiUrl = "http://localhost:7545"; //Replace with your API

    var httpClient = new Client();

    var credentials = Credentials.fromHexPrivateKey(privateKeyHex);
    var client = new Web3Client(apiUrl, httpClient);

    //Set up a new transaction
    new Transaction(keys: credentials, maximumGas: 100000)
    .prepareForSimpleTransaction( //that will transfer 2 ether
        EtherAmount.fromUnitAndValue(EtherUnit.ETHER, 2))
    .send(client); //and send.

Feature requests and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.2 #

  • Send transactions and call messages from smart contracts on the Blockchain.

0.1 #

  • Create new Ethereum accounts

0.0.2 #

  • Send and sign transactions

0.0.1 #

  • Initial version, created by Stagehand


import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';

const String _PRIVATE_KEY = "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3";
const String _URL = "http://localhost:7545";

main() async {
	var httpClient = new Client();
	Web3Client client = new Web3Client(_URL, httpClient);
	client.printErrors = true;

	var credentials = Credentials.fromHexPrivateKey(_PRIVATE_KEY);

	//Set up a new transaction
	new Transaction(keys: credentials, maximumGas: 100000)
		.prepareForSimpleTransaction( //that will transfer 2 ether
			EtherAmount.fromUnitAndValue(EtherUnit.ETHER, 2))
		.send(client); //and send.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  web3dart: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:web3dart/web3dart.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0