Ethers: A dart library that connects to interact with the Ethereum blockchain and inspired by ethers.js

Overview

Ethers For Flutter

test

Ethers is a dart library that connects to interact with the Ethereum blockchain and inspired by ethers.js.

Thanks to web3dart which is no longer maintained.

Installing

Add Ethers to your pubspec.yaml file:

dependencies:
  ethers:

Import Ethers in files that it will be used:

import 'package:ethers/ethers.dart';

Usage

const provider = new ethers.providers.JsonRpcProvider();

// Look up the current block number
await provider.getBlockNumber();
// 14135476

// Get the balance of an account (by address or ENS name, if supported by network)
final balance =
    await provider.getBalance("0x0000000000000000000000000000000000000000");
// { BigInt: "10478645750785322678769" }

// Often you need to format the output to something more user-friendly,
// such as in ether (instead of wei)
ethers.utils.formatEther(balance);
// '10478.645750785321'

// If a user enters a string in an input field, you may need
// to convert it from ether (as a string) to wei (as a BigNumber)
ethers.utils.parseEther("1.0");
// { BigInt: "1000000000000000000" }

Wallet

// Create a wallet instance from a mnemonic...
final mnemonic = "announce room limb pattern dry unit scale effort smooth jazz weasel alcohol"
final walletMnemonic = Wallet.fromMnemonic(mnemonic);

// ...or from a private key
final walletPrivateKey = Wallet(walletMnemonic.privateKey);

walletMnemonic.address == walletPrivateKey.address;
// true

// The address as a Promise per the Signer API
walletMnemonic.getAddress()
// '0x71CB05EE1b1F506fF321Da3dac38f25c0c9ce6E1'

// The address as a Promise per the Signer API
walletMnemonic.address
// '0x71CB05EE1b1F506fF321Da3dac38f25c0c9ce6E1'

// The internal cryptographic components
walletMnemonic.privateKey
// '0x1da6847600b0ee25e9ad9a52abbd786dd2502fa4005dd5af9310b7cc7a3b25db'
walletMnemonic.publicKey
// '0x04b9e72dfd423bcf95b3801ac93f4392be5ff22143f9980eb78b3a860c4843bfd04829ae61cdba4b3b1978ac5fc64f5cc2f4350e35a108a9c9a92a81200a60cd64'

// The wallet mnemonic
walletMnemonic.mnemonic
// {
//   locale: 'en',
//   path: "m/44'/60'/0'/0/0",
//   phrase: 'announce room limb pattern dry unit scale effort smooth jazz weasel alcohol'
// }

// Note: A wallet created with a private key does not
//       have a mnemonic (the derivation prevents it)
walletPrivateKey.mnemonic
// null

TODO...

You might also like...

Chopper is an http client generator using source_gen and inspired from Retrofit.

Chopper is an http client generator using source_gen and inspired from Retrofit.

Chopper Chopper is an http client generator for Dart and Flutter using source_gen and inspired by Retrofit. Documentation Installation Please refer to

Dec 31, 2022

Modern and elegant test framework for Flutter, inspired by Cypress

Modern and elegant test framework for Flutter, inspired by Cypress

flutter_modern_test: Modern, elegant and productive test framework for Flutter, inspired by Cypress GitHub: https://github.com/fzyzcjy/flutter_modern_

Oct 19, 2022

Dependency Injection oversimplified. Inspired by Koin, with focus on scopes.

Dependency Injection oversimplified. Inspired by Koin, with focus on scopes. Features Define your dependencies in a syntax as close to DSL as possible

Dec 5, 2022

Releases for the Delta-y app: A scrum-inspired personal productivity app for data-nerds with goals

Releases for the Delta-y app: A scrum-inspired personal productivity app for data-nerds with goals

Delta-y Releases This repository contains the public releases for the Delta-y app, which is currently closed source. Resources delta-y-flyer.pdf Video

Dec 10, 2021

Medikkare is a doctor appointment app. Written in Flutter. Inspired by Dribbble.

Medikkare is a doctor appointment app. Written in Flutter. Inspired by Dribbble.

Medikkare is a doctor appointment app. Written in Flutter. Inspired by Dribbble.

Jan 1, 2023

Pet Adoption App concept built with Flutter inspired by Aman UX

Pet Adoption App concept built with Flutter inspired by Aman UX

🐶 Adopt Me 🐹 Pet Adoption App concept built with Flutter inspired by Aman UX.

Dec 8, 2022

A Dart library for creating a Dart object to represent directory trees.

Directory Tree A Dart library for creating a Dart object to represent directory trees. Getting Started Import and initialize package import 'package:d

Dec 1, 2021

A fast and space efficient library to deal with data in Dart, Flutter and the web.

Dart Data Dart Data is a fast and space efficient library to deal with data in Dart, Flutter and the web. As of today this mostly includes data struct

Nov 4, 2022

Postgres-conector - A library for connecting to and querying PostgreSQL databases in Dart.

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Nov 14, 2021
Comments
  • QUESTION: Error during initialisation

    QUESTION: Error during initialisation

    Hi @Hanggi ,

    I have added the ethers package and imported the package as instructed in the current README . I am currently having this error on the next step.

    const provider = new ethers.providers.JsonRpcProvider();
    

    ERROR

    error: Const variables must be initialized with a constant value.

    error: The prefix 'ethers' can't be used here because it is shadowed by a local declaration.

    image

    Kindly assist if you can. Thanks in advance.

    opened by bisi-dev 1
  • NoSuchMethodError: No top-level method '_WNafMultiplier' declared.

    NoSuchMethodError: No top-level method '_WNafMultiplier' declared.

    Error when running the example

    final mnemonic = "announce room limb pattern dry unit scale effort smooth jazz weasel alcohol";
    
    final wallet = Wallet.fromMnemonic(
      mnemonic,
      path: "m/44'/60'/0'/0/0",
    );
    
    print('address: ${wallet.address}');
    

    ERROR

    [ERROR:flutter[/lib/ui/ui_dart_state.cc]()(209)] Unhandled Exception: NoSuchMethodError: No top-level method '_WNafMultiplier' declared.
    Receiver: top-level
    Tried calling: _WNafMultiplier(Instance of 'ECPoint', Instance of '_BigIntImpl', Instance of '_WNafPreCompInfo')
    #0      NoSuchMethodError._throwNewInvocation (dart:core-patch[/errors_patch.dart:207:5]())
    #1      ECPointBase.*
    package:pointycastle/ecc/ecc_base.dart:153
    #2      pointFromScalar
    package:bip32/…/utils/ecurve.dart:93
    #3      BIP32.publicKey
    package:bip32/src/bip32_base.dart:40
    #4      HDNode._nodeFromRoot (package:ethers[/utils/hdnode/hd_node.dart:88:49]())
    #5      new HDNode._fromSeed (package:ethers[/utils/hdnode/hd_node.dart:115:12]())
    #6      new HDNode.fromMnemonic (package:ethers[/utils/hdnode/hd_node.dart:123:19]())
    #7      new Wallet.fromMnemonic (package:ethers[/signers/wallet.dart:95:37]())
    #8      MainScreen.build.<anonymous closure>
    package:testing/main.dart:61
    #9      MainScreen.build.<anonymous closure>
    package:testing/main.dart:47
    #10     _InkResponseState._handleTap
    package:flutter/…/material/ink_well.dart:989
    #11     GestureRecognizer.invokeCallback
    package:flutter/…/gestures/recognizer.dart:198
    #12     TapGestureRecognizer.handleTapUp
    package:flutter/…/gestures/tap.dart:608
    
    opened by oliverbytes 0
Owner
Hanggi
No Game No Life
Hanggi
A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background which in turn increases your credit score.

Sahayog A simple easy to use Flutter DApp , which keeps a track of all your day to day transactions by using Ethereum blockchain in the background whi

Utkarsh Agarwal 15 May 21, 2022
A decentralized application for bidding on Ethereum blockchain.

auction_dapp A decentralized application for bidding on Ethereum blockchain. Setting up the development environment Install Node.js and Npm from here

OpenCode IIIT Allahabad 10 Dec 13, 2022
Dig is a hub blockchain that interconnects physical plots of land, which will each be governed by a locally operated blockchain.

Dig is a hub blockchain that interconnects physical plots of land, which will each be governed by a locally operated blockchain. Due to the regulatory challenges involved, dig splits itself up into many chains which can each follow appropriate legislation. This is the beginning of the "Dig Network."

notional-labs 183 Dec 17, 2022
The Fuse Wallet is a cross platform Ethereum wallet written in Dart and built on Flutter.

Fuse Wallet The Fuse Wallet is a cross platform Ethereum wallet written in Dart and built on Flutter. It's runninng on the Fuse network, but can be pl

null 4 Nov 9, 2022
Web3 Ethereum, Etherjs and Wallet Connect wrapper for Flutter Web.

flutter_web3 This is a fork of flutter_web3_provider. Be sure to check out the original package. Introduction flutter_web3 v2 is full Dart class and f

yoisha 105 Jan 2, 2023
A mock library for Dart inspired by mockito

?? mocktail This repository contains mocking libraries for Dart inspired by mockito. package:mocktail A Dart mocking library which simplifies mocking

Felix Angelov 430 Dec 25, 2022
BlockChain Project

Blockchain BlockChain Project github repo This project is made using blockchain which an to-do application for mobile .I have used ,Flutter as it's a

himanshu chaurishiya 3 May 8, 2022
Concepts used Flutter layout,State management, Blockchain integration, Http api integration, Smart contracts

HS_CryptoCoin_Wallet First project using Flutter with Blockchain Getting Started This project is a starting point for a Flutter application. A few res

Harsh Saxena 1 Dec 23, 2021
⚡⚡ flutter mobile dapp to register/mint domain names (.voltz) on the polygon blockchain network (mumbai)

open-name-service connecting to wallet registering a domain on the network fetching address by domain name & viewing domain on opensea testnet .voltz

Chinyeaka Chinonso 10 Dec 11, 2022
This is a Flutter project inspired by sustainability and powered by the community

This is a Flutter project inspired by sustainability and powered by the community. TrashTrack is a demo of a social platform with geolocation features that brings people a new way of collaboration.

David 0 Oct 31, 2021