/dapp-beta-faucet

Faucet contract and Lambda functions for Ropsten & Rinkeby to auto-send testers Ether and ERC20 tokens

Primary LanguageJavaScriptApache License 2.0Apache-2.0

ĐApp Faucet Contract & Lambda Functions
PRs Welcome

What is this?

This is an automated Ethereum agent which signs and calls Ethereum smart contract functions on your behalf via AJAX/XHR GET requests to lambda endpoints. We use it to remove the friction of providing Ether and ERC20 Tokens to our Beta Testers.

You can read the blog post here: https://medium.com/p/fe18b3267c04

Table of contents

Example

(Back to top)

A simple example of our Hippocrates ĐApp's frontend showing what this can look like to your beta testers:

Frontend Example Gif

Installation

(Back to top)

Prerequisites

You will need the direnv tool to export environment variables specifically for this project. You can get instructions on how to install it for your machine here: https://direnv.net/

Install Node/NPM Packages

$ npm install

Testing the Contracts

To run the truffle tests:

$ npm run test

Environment Variables

Prior to running truffle, the ganache-cli server or the lambda functions you will need to set up your environment variables. Copy the .envrc.example file to .envrc, and update your new .envrc with your unique environment variables:

  1. cp .envrc.example .envrc

  2. Enter your own wallet's twelve word mnemonic in the .envrc file.

  3. Also, we'll leverage Infura's Ethereum Ropsten testnet node, so make sure to set up an account and paste your private key in your .envrc.

  4. Use direnv allow to export the env vars into your current terminal shell.

Running

(Back to top)

Run the Ganache-CLI server:

The Ganache server acts as a local test Ethereum blockchain and EVM:

$ npm run start

Compile and migrate the contracts locally:

With the Ganache server running you can now compile and migrate (deploy) your contracts to the blockchain. To do this locally run:

npm run migrate

If you want to do this against the Ropsten or Rinkeby blockchains, use:

npm run migrate -- --network=ropsten or npm run migrate -- --network=rinkeby

Filling up your newly deployed BetaFaucet contract:

If you want your contract to send Ether, you will first need to send Ether to your newly deployed contract. Same goes for any ERC20 token, the contract will need a balance that it can then hand out.

Ensuring an ERC20 Token balance:

We use truffle console to send Ether and mint ERC20 token to our deployed BetaFaucet instance. If your BetaFaucet was deployed to the address '0x847e024dfabcacd68cb2c2d120d195ccba4c4484', and your ERC20 token contract was deployed to '0x736768bb1acea596134f39b68bfb877286dd2220' you can mint tokens directly to the deployed BetaFaucet contract.

YTKNToken.at('0x736768bb1acea596134f39b68bfb877286dd2220').then(i => ytknInstance = i)

ytknInstance.mint('0x847e024dfabcacd68cb2c2d120d195ccba4c4484', '100000000000000000000000')

Topping up Ether

You can easily send your deployed contract Ether via MetaMask, MyCrypto or any other wallet - just as you would send Ether to any other Ethereum address.

If you've deployed your contracts to Ropsten, you can get test Ropsten Ether on any of these faucets:

Run the faucet lambda endpoint server:

While your Ganache-CLI server is running (via npm run start) open another terminal window and install the npm packages in the lambda dir:

$ cd lambda
$ npm i
$ cd ..

Then use npm run lambda to compile the lambda functions and start a server at http://localhost:9000

An example of having the contract send you Ether would be to make the following GET request:

http://localhost:9000/betaFaucetSendEther?ethAddress=0x95819594aeb3d6d5abb338b263e944b56dd2f195

Troubleshooting

Where is my private key?

After generating your mnemonic and adding it to your .envrc file, allowing those env vars using direnv allow, and running the Ganache-CLI server with npm run start you can find your contract owner's private key at the top of the logs, as the first private key (0):

Finding Your Private Key

I found a bug!

Awesome! Feel free to open a new Issue or even better, a Pull Request with the fix!

What is Lambda?

From Amazon's FAQ:

AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time you consume - there is no charge when your code is not running.

We use Netlify's Lambda integration. Their 'Functions Free' plan provides you with up to 125,000 requests / month and up to 100 hours of run time / month. You can find more on that here: https://www.netlify.com/docs/functions/

Contributing

(Back to top)

Your contributions are always welcome! Please open a new Issue or Pull Request to contribute. 😄

License

(Back to top)

The Apache License January 2004. Please have a look at the LICENSE for more details.

Who Built This?

(Back to top)

OSS project provided by:

MedCredits Logo

Visit MedCredits.io

Code authored by:

Brendan Asselstine & Chuck Bergeron