web3dart 0.2.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 49

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

TODO

  • Code generation based on smart contract ABI for easier interaction
  • Smart Contract events
  • Encode all supported solidity types, although only tuple and (u)fixed, which are not commonly used, are not supported at the moment.

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
        "0xf17f52151EbEF6C7334FAD080c5704D77216b732",
        EtherAmount.fromUnitAndValue(EtherUnit.ETHER, 2))
    .send(client); //and send.
    }

See example/crypto_kittens_example.dart for an example on how to call methods from smart contracts deployed on the blockchain.

Feature requests and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.2.1

  • More solidity types, not with encoding.

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

example/web3dart_example.dart

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
			"0xf17f52151EbEF6C7334FAD080c5704D77216b732",
			EtherAmount.fromUnitAndValue(EtherUnit.ETHER, 2))
		.send(client); //and send.
}

1. Depend on it

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


dependencies:
  web3dart: "^0.2.1"

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';
        
Version Uploaded Documentation Archive
0.2.1 Jan 17, 2018 Go to the documentation of web3dart 0.2.1 Download web3dart 0.2.1 archive
0.2.0 Jan 15, 2018 Go to the documentation of web3dart 0.2.0 Download web3dart 0.2.0 archive
0.1.0 Jan 14, 2018 Go to the documentation of web3dart 0.1.0 Download web3dart 0.1.0 archive
0.0.2 Jan 13, 2018 Go to the documentation of web3dart 0.0.2 Download web3dart 0.0.2 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
95 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
49

Platforms

Detected platforms: web, other

Primary library: package:web3dart/web3dart.dart with components: mirrors.

Suggestions

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
bignum ^0.1.0 0.1.0
convert ^2.0.1 2.0.1
http ^0.11.3+16 0.11.3+16
meta ^1.1.2 1.1.2
pointycastle ^0.10.0+5 0.10.0+5 0.11.1
tuple ^1.0.1 1.0.1
Transitive dependencies
analyzer 0.30.0+4 0.31.0+1
args 1.3.0
async 2.0.3
barback 0.15.2+14
charcode 1.1.1
cli_util 0.1.2+1
code_transformers 0.5.1+4
collection 1.14.5
crypto 2.0.2+1
csslib 0.14.1
dart_style 1.0.9+1
fixnum 0.10.6
front_end 0.1.0-alpha.4.1 0.1.0-alpha.8
glob 1.1.5
html 0.13.2+2
http_parser 3.1.1
isolate 1.1.0
kernel 0.3.0-alpha.1.1 0.3.0-alpha.5
logging 0.11.3+1
package_config 1.0.3
path 1.4.2 1.5.1
plugin 0.2.0+2
pool 1.3.4
quiver_collection 1.0.0
quiver_hashcode 1.0.0
quiver_iterables 1.0.1
quiver_pattern 1.0.0
reflectable 1.0.4 2.0.0-dev.1.0
source_maps 0.10.4
source_span 1.4.0
stack_trace 1.9.1
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+7
yaml 2.1.13
Dev dependencies
test ^0.12.0