Testnets – How to Create a Faucet for an Ethereum Private Network: Cloning https://faucet.ropsten.be

faucetstestnets

I have set up a Ethereum Network with 5 nodes on azure. Now I want to make a faucet like https://faucet.ropsten.be/ .Where anyone can go and put there wallet address and can get my network testether. So for this I have deployed a smart contract on my network . In that smart contract a function is there which users will have to execute to get the testether. But because they don't have any testether so they cannot pay the gas for the function execution for this I will have to implement a solution in which gas is paid by the smart contract itslef which is storing the testether of my network.So for this the solution is a little complex will have to use signing transaction and all like in this article(Create a faucet for Ethereum Private network to get Ethers I was wondering if anyone can suggest an easy solution in which my send user just out his/her wallet address and click a button on frontend and they get the testether without showing them any signing and anything just like rinkbey or ropsten testnet faucet.

Best Answer

After trying I figured it out that we can make faucet as a traditional client-server web application. For this, we can store a lot of ethers in an external wallet(you can send a lot of ether manually from geth console to this wallet which is sending ether from the server). The given below code for running a server. Access this http://localhost:3000/sendtx. This will send 1 ether to a wallet address which provided. I have used this article to answer https://medium.com/coinmonks/ethereum-tutorial-sending-transaction-via-nodejs-backend-7b623b885707 You can make a frontend for this with a button and a form to input a

const web3 = require('web3');
const express = require('express');
const Tx = require('ethereumjs-tx');
const app = express();
web3js = new web3(new web3.providers.HttpProvider("https://rinkeby.infura.io/YOUR_API_KEY")); //You can use your costom RPC also
app.get('/sendtx',function(req,res){
    var myAddress = 'Your address';//'ADDRESS_THAT_SENDS_TRANSACTION';
    var privateKey = Buffer.from('PrivateKey', 'hex')
    var toAddress = '0x';//Address to which sending transaction.
    var amount = 1000000000000000000 //in wei

    web3js.eth.getTransactionCount(myAddress).then(function(v){
        console.log("Count: "+v);
        count = v;
        //creating raw tranaction
        var rawTransaction = {"from":myAddress, "gasPrice":web3js.utils.toHex(20* 1e9),"gasLimit":web3js.utils.toHex(210000),"to":toAddress,"value":web3js.utils.toHex(amount),"data":"0x0","nonce":web3js.utils.toHex(count)}
        console.log(rawTransaction);
        //creating tranaction via ethereumjs-tx
        var transaction = new Tx(rawTransaction);
        //signing transaction with private key
        transaction.sign(privateKey);
        //sending transacton via web3js module
        web3js.eth.sendSignedTransaction('0x'+transaction.serialize().toString('hex'))
        .on('transactionHash',console.log);
    })
});
app.listen(3000, () => console.log('Example app listening on port 3000!'))
Related Topic