Code Monkey home page Code Monkey logo

smartnsoft / android-monero-miner Goto Github PK

View Code? Open in Web Editor NEW
24.0 23.0 12.0 301 KB

A minimal SDK that lets an integrator add a Monero Miner using the Javascript miner created by CoinHive. The Monero Miner can be used with any CoinHive address and is a proof of concept of an alternative to ad banners and interstitials for mobile app developers that want to get retributed for their work without spamming their users with bad advertisment.

License: MIT License

Kotlin 80.77% HTML 8.07% Java 11.16%
android monero miner sdk coinhive javascript kotlin

android-monero-miner's Introduction

Download License: MIT TeamCity status

android-monero-miner

A minimal SDK that lets an integrator add a Monero Miner using the Javascript miner created by CoinHive. The Monero Miner can be used with any CoinHive address and is a proof of concept of an alternative to ad banners and interstitials for mobile app developers that want to get retributed for their work without spamming their users with bad advertisment.

Prerequisites

You must create a CoinHive account

https://coinhive.com

Get then your public Site key

https://coinhive.com/settings/sites

This will be used to initialize your Monero Miner in Android.

How it works

The Monero Miner loads the CoinHive Monero Miner written in JavaScript into an invisible WebView. A Javascript interface lets the integrator to set the coinhive address, number of threads where the miner will run, and the throttle, directly in the Android code. The instructions are then injected into the Javascript code.

Initialization

The MoneroMiner follows the Singleton pattern. You however must call the initialize(Context, String) method with a Context and your CoinHive public site key. You can do this in the onCreate() method of your Application

MoneroMiner.INSTANCE.initialize(getApplicationContext(), COINHIVE_ADDRESS);

Use the Monero Miner

Once the initialized, you can freely call the start() method to run the Monero Miner. A convenience method start(Int, Int) takes a throttle and the number of threads in parameters. When not used anymore, call the stop() method.

Parameters

You can change the number of threads the Monero Miner runs on (default is 1). Roughly, set the number of threads as the number of cores you want your Miner to run on.

MoneroMiner.setThreads(1);

You can change the throttle of the Monero Miner (default is 20). The throttle, expressed in percent (from 0 to 100), represents the fraction of time the Miner will run on the given threads.

MoneroMiner.setThrottle(20);

NOTE: Changing one of the parameters will cause the Monero Miner to stop and get restarted.

Download

Gradle

implementation("com.smartnsoft:monerominer:${latest.version}")

Known Issues

Windows Defender is known to block the use of the Monero Miner script onto your Windows distribution. If you get an error when starting or initializing the miner stating that it cannot find a reference to coinhive.js, make sure you have desactivated Windows Defender first.

Further improvements

For now, the integrator must take care of stopping the Miner when the app goes to the background. A further improvement may be to make this automatically. Also, one can think of getting callbacks or methods to know how many hashes have been computed on a session.

License

This SDK is under the MIT license.

Author

This Monero Miner was proudly made at Smart&Soft, Paris FRANCE

android-monero-miner's People

Contributors

david-fournier-smartnsoft avatar ludovicroland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-monero-miner's Issues

Uncaught ReferenceError

Hi

I have an error in this SDK after mining start:

"Uncaught ReferenceError: CoinHive is not defined", source: file:///android_asset/monero-miner.html (17)

Coinhive Error: source: file:///android_asset/coinhive.js (436)

I'm getting this logcat output after running the start() method. I have Windows Defender disabled so I don't think it's because of that.

Full message:
I/chromium: [INFO:CONSOLE(436)] "Coinhive Error:", source: file:///android_asset/coinhive.js (436)

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.