Git Product home page Git Product logo

meteor-package-blocks's Introduction

Ethereum blocks

Provides you with an EthBlocks collection, which stores the last 50 blocks.

You can query blocks like any other Meteor collection.

Installation

$ meteor add ethereum:blocks

Usage

Initialize Blocks on the start of your application, as soon as you have a ethereum connection:

EthBlocks.init();

Last block

To get the latest block use:

EthBlocks.latest;

Note this property is reactive, so it will re-run your reactive functions, e.g. when used in template helpers.

In case you want to update the latest block you can change properties as follows:

EthBlocks.latest = { hash: "12345" };

This would only change the hash property of the latest block, but leave all other properties as is.

Current gas price

Additionally all blocks get the current gasprice add:

EthBlocks.latest.gasPrice; // '1136672632018' (wei)

Detecting forks

You can call Blocks.detectFork(callback) to detect chain re-organisation (forks), while your applications is running. This detection, is checking the new incoming blocks parentHash, with the last known block you have.

Note The fork detection can currently be wrong, when you're importing blocks, as they can come in different orders.

EthBlocks.detectFork(function(oldBlock, newBlock) {
  // this callback will be fired with the old block we knew and the new block.
});

Note you can call EthBlocks.detectFork(cb) mutliple times, to add multiple callbacks.

Clear all stored blocks

If you switch to a chain, which has a lower block number EthBlocks will reset your interally cache of the last 50 blocks. If you want to do that manually call:

EthBlocks.clear();

meteor-package-blocks's People

Contributors

frozeman avatar hiddentao avatar ryanio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.