0

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.

3 Answers 3

1

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!'))
0

Without any first thought, this is a very well-formed chicken-egg-first problem- i.e. a user in the network needs tokens to run a contract, but the user needs to run a contract to get tokens!

Here's how you achieve the desired result:

  1. The place where the user is clicking the button on your frontend is basically the DApp frontend. Let's say the user enters an address, amount, and then clicks on the button to receive the amount of testether.

  2. You do some basic validation on the form, make sure there are not too many requests from the same user, etc.

  3. Now take the user's request, and make a transaction on behalf of the user. This is where you'll need web3.js or web3.py kind of interface to interact with your local ethereum network.

Last point i.e. 3 is all the work you'll need to do. I would personally put some amount of ether in another address(es) when deploying and starting my local network. Then I'll make on of these addresses the contract owner/ or a delegate which can transfer testether to a user. And as I outlined above, upon receiving a request from a user, I make a transaction for the testether request.

0

if you used puppeth to set it up it has a faucet build in, a web wallet etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.