Netherum Faucet and Nuget templates
Every time that a new development environment is setup to work with Ethereum, we have the problem to distribute Ether to different accounts. Faucets allow developers (or users) to have a self-serve mode to fund their accounts with Ether.
How does this faucet work?
One of the problems of faucets is how to limit the amounts users get, or they will end up emptying the faucet.
For this simple faucet, 2 approaches have been taken. 1 limit the amount that is sent each time, and do not send any Ether to accounts that already have some Ether above a certain limit.
The overall business logic is reduced to few lines of code in the controller
var account = new Account(settings.FunderPrivateKey);
var web3 = new Web3(account, settings.EthereumAddress);
First, we create a new instance of Web3 with the RPC address of our node, and an instance of an Account with its private key.
Afterwards we validate the balance of the account of the address to receive the funds.
var balance = await web3.Eth.GetBalance.SendRequestAsync(faucetViewModel.Address);
if (web3.Convert.FromWei(balance.Value) > settings.MaxAmountToFund)
ModelState.AddModelError("address", "Account cannot be funded, already has more than " + settings.MaxAmountToFund + " ether");
And if they don’t have enough funds we send the default amout
var txnHash = await web3.Eth.TransactionManager.SendTransactionAsync(
To configure your settings open Appsettings.json and set the values for the different amounts, your private key and transaction explorer.
dotnet new Nuget Templates
Needless to say you can clone the code from the repo and deploy it to Azure websites, (it will be a good idea to have a deploy to azure button on the repo), linux, docker or whatever your favourite dotnet core host is.
The faucet can also now be installed as one of the new “dotnet new” templates. These templates are similar to Yeoman, but now, can be deployed via nuget, providing the capability for different versions of the same template.
The plan for Nethereum is to start creating many templates which facilitates to get started with Ethereum for every type of integration, and the faucet is the first one of (hopefully) many more to come.
To install the template you can simply run:
dotnet new -i Nethereum.Templates.Faucet::*
The suffix of ::* means that you want the latest version of the Nuget template package.
Now if “dotnet new” is ran, it will appear as one of the templates
And a faucet site can be created simply using the following command
dotnet new nethereumfaucet -n BankConsortiumFaucet
Where -n indicates the namespace of the faucet