web3dart 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 40

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.

TODO #

  • Interact with smart contracts deployed on the Ethereum blockchain.
  • Key/Account generation.

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: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 credentials = Credentials.fromHexPrivateKey(privateKeyHex);
var client = new Web3Client(apiUrl);

//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.
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.0.2 #

  • Send and sign transactions

0.0.1 #

  • Initial version, created by Stagehand

example/web3dart_example.dart

import 'package:web3dart/web3dart.dart';

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

main() async {
	Web3Client client = new Web3Client(_URL);
	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.
}

Use this package as a library

1. Depend on it

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


dependencies:
  web3dart: ^0.0.2

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
40
Learn more about scoring.

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.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

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