Coder Social home page Coder Social logo

pinkdiamond1 / pow-faucet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crackerli/pow-faucet

0.0 1.0 0.0 2.27 MB

Proof of Work Faucet for NEAR accounts to gain Ⓝ (NEAR denomination) from a React app.

Home Page: https://near-examples.github.io/pow-faucet/

License: MIT License

Shell 0.73% JavaScript 51.52% Rust 39.00% HTML 8.75%

pow-faucet's Introduction

Proof of Work Faucet

A cryptocurrency "faucet" is a site that gives away cryptocurrency. Faucets are especially common on test networks such as NEAR TestNet to allow developers to test apps with tokens which have no monetary value.

Faucets can run out of tokens, especially if people abuse them and purposely attempt to drain available funds. While test network tokens can be replenished one way or another, doing so can be a hassle, so it's useful to deter this sort of behavior.

To this end, some faucets require that token requests be accompanied by a post on Twitter. But it's easy for one person to spin up many fake Twitter accounts to drain a faucet. This sort of behavior would be classified as a Sybil attack.

This demo uses a different approach.

First, each new account created with this faucet receives 1/1000 of the funds remaining at the time it was created.

Second, this faucet requires Proof of Work: before the faucet creates your new account, you need to wait while the JavaScript on the page churns through some complex computation (in this demo, that specific computation is to compute a u64 salt for a given account id + public key in such a way that the sha256(account_id + ':' + public_key + ':' + salt) has min_difficulty leading zeroes).

Try it out

You can try out a live version of this demo: https://near-examples.github.io/pow-faucet/

This demo version creates new NEAR TestNet accounts with a .meta suffix.

Playing with the Code

The code lives in two different places:

Faucet Contract

The smart contract source code lives in the contract-rs folder, and specifically in contract-rs/src/lib.rs.

After you make changes, run tests by entering the contract-rs directory (cd contract-rs) and running:

cargo test

To recompile the smart contract in preparation for deploying it, again enter the contract-rs directory and run:

./build.sh

Faucet Frontend

This contains the JavaScript that shows the UI and runs the proof-of-work algorithm. It lives in the frontend folder.

It was bootstrapped with create-react-app. Check out the https://github.com/near-examples/pow-faucet/blob/master/frontend/README.md in the frontend folder to learn how to play with the code.

Deploying

The Contract and the Frontend need to be deployed separately.

Contract

Quickest deploy

Build and deploy this smart contract to a development account. Dev Accounts are auto-generated accounts to assist in developing and testing smart contracts. Please see the Standard deploy section for creating a more personalized account to deploy to.

near dev-deploy --wasmFile res/faucet.wasm

Behind the scenes, this is creating an account and deploying a contract to it. On the console, notice a message like:

Done deploying to dev-1234567890123

In this instance, the account is dev-1234567890123. A file has been created containing a key pair to the account, located at neardev/dev-account. To make the next few steps easier, we're going to set an environment variable containing this development account id and use that when copy/pasting commands. Run this command to the environment variable:

source neardev/dev-account.env

You can tell if the environment variable is set correctly if your command line prints the account name after this command:

echo $CONTRACT_NAME

The next command will initialize the contract using the new method:

near call $CONTRACT_NAME new '{"account_suffix":"aloha", "min_difficulty": 10}' --accountId $CONTRACT_NAME

To retrieve the number of created accounts, call get_num_created_accounts with the following:

near call $CONTRACT_NAME get_num_created_accounts '' --accountId $CONTRACT_NAME

Standard deploy

Frontend

  • The frontend compiles to static assets – HTML, CSS, and JavaScript. The demo frontend is deployed to GitHub Pages using gh-pages. Feel free to re-use this approach or find another.

See Also

As a follow-up to this demo, we created a Proof of Work Transfer Faucet. This "Transfer Faucet" differs from the current example in two main ways:

  1. Rather than create a new account, it sends NEAR Tokens to an existing account
  2. Rather than send 1/1000th of the remaining funds, it always sends 100Ⓝ

Data collection

By using Gitpod in this project, you agree to opt-in to basic, anonymous analytics. No personal information is transmitted. Instead, these usage statistics aid in discovering potential bugs and user flow information.

pow-faucet's People

Contributors

dependabot-preview[bot] avatar thisisjoshford avatar janedegtiareva avatar dependabot[bot] avatar chadoh avatar mikedotexe avatar bucanero avatar vgrichina avatar tarasenkofirelabs avatar buckram123 avatar evgenykuzyakov avatar volovyks avatar

Watchers

 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.