GithubHelp home page GithubHelp logo

dartminer's Introduction

Dartminer - An example bitcoin mining package written in Dart.

This is an example application of how to build a Bitcoin mining application using the Dart language. I also recommend only using this application using the TestNet within Bitcoin so that you do not risk of hitting the live network with sample code.

On my machine, I was able to hit hash rate of about 500kH/s, which turns out to be about a 15x speed improvement on a JavaScript implementation... While this is impressive, here's hoping that the Dash VM improves in performance with future releases.

Usage

Below is the steps necessary to get this to work.

Mining with getwork.

import 'package:dartminer/dartminer.dart';
 
 // Our main entry point.
void main() {  
  
  // Create a bitcoin client with the proper configuration.  
  Bitcoin bitcoin = new Bitcoin({
    "scheme": "http",
    "host": "127.0.0.1",
    "port": 18332,
    "user": "bitcoinrpc",
    "pass": "123123123123"
  }, new RPCRequest());
  
  // Get work from the bitcoind.
  bitcoin.getwork().then((Map<String, String> work) {
    
    // Work.
    print(work);
    
    // Create the miner.
    Miner miner = new Miner.fromJSON(work);
    
    // Mine for gold!
    Map<String, String> result = miner.mine();
    
    // If the result isn't null, then
    if (result != null) {
      print('Gold!');
      print(result);
      bitcoin.getwork(params: [result['data']]);
    }
  });
}

Mining with getblocktemplate

// Import the dartminer package.
import 'package:dartminer/dartminer.dart';

// Our main file
void main() {  
  
  // Create a bitcoin client with the proper configuration.  
  Bitcoin bitcoin = new Bitcoin({
    "scheme": "http",
    "host": "127.0.0.1",
    "port": 18332,
    "user": "bitcoinrpc",
    "pass": "123123123123123"
  }, new RPCRequest());
    
  // Get work from the bitcoind.
  bitcoin.getblocktemplate().then((dynamic tpl) {
    
    // Create the new template.
    Template template = new Template.fromJSON(tpl, address: '1N438cAaGjY9cyZ5J5hgvixkch3hiu6XA1');
    
    // Mine for gold.
    Map<String, String> result = template.mine();
    
    // See if there is a result.
    if (result != null) {
      
      // We found gold!
      print('GOLD!');
      
      // Print the result.
      print(result);
      
      // Submit the block.
      bitcoin.submitblock(params: [result['data']]);
    }
  });
}

Donations Welcome: 1N438cAaGjY9cyZ5J5hgvixkch3hiu6XA1

Enjoy...

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.