Skip to content
/ pow-faucet Public template

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

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE-APACHE
Notifications You must be signed in to change notification settings

crackerli/pow-faucet

Repository files navigation

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 README in the frontend folder to learn how to play with the code.

Deploying

The Contract and the Frontend need to be deployed separately.

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.

About

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

Resources

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE-APACHE

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published