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.

Libraries

web3dart
Support for doing something awesome. [...]