I'm having some trouble wrapping my mind around the creation of ERC20 faucets. How exactly is this done? I have created a token (https://ropsten.etherscan.io/token/0x90de67a867b18535ad558fec0c418921340ffc91?a=0x18c59adbf99be137b3eeaffd84b083fd623a4c36) but I'm not sure how I would go about distributing tokens utilizing a faucet. This is purely for testing purposes but I'd like to be able to give away diminishing values of this test token based on the previous amount given out.

I'm assuming I'll need to use Transfer(), which I used in my getFromFaucet() function, but I'm extremely confused as to how to even get these tokens to be sent to a different address.

function getFromFaucet(address _to) returns (bool success) {
        uint256 giveaway_value;

        if (previous_giveaway == 0){
            giveaway_value = starting_giveaway;
            previous_giveaway = starting_giveaway;
        previous_giveaway = previous_giveaway / 2;

        if (balances[msg.sender] >= giveaway_value){
            balances[msg.sender] -= giveaway_value;
            balances[_to] += giveaway_value;
            Transfer(msg.sender, _to, giveaway_value);
            return true;
        else return false;

Like, how do I call this getFromFaucet and pass the address to it? I'm planning on distributing from a website.

Thanks in advance!

1 Answer 1


You are writting a complex transfer function, the only difference is the sender cannot control the amount given away.

If you want to create a token faucet I'd make the recipient to send the transaction. Also having a cool down period of two minutes to limit possible abuse.

uint previous_giveaway;
uint last_giveaway;

function drip() returns (bool success) {
    // Only allow to drip every two minutes to limit abuse
    if (now - last_giveaway < 2 minutes) {
        return false;
    last_giveaway = now;
    // deliver half than last time
    uint giveaway_value = previous_giveaway / 2;
    if (giveaway_value == 0){
        giveaway_value = starting_giveaway;
        previous_giveaway = starting_giveaway;
    // It is a faucet mint new tokens
    balances[msg.sender] += giveaway_value;
    totalSupply += giveaway_value;
    Transfer(0x0, msg.sender, giveaway_value);
    return true;

To call that contract from a webapp using web3 v1.0 something like this should work

const token = new eth.Contract(abiToken, addressToken);
await token.methods.drip().send({ from: "address" });

The contract will deposit a few tokens to "address".

  • the complexity of the function is not what's confusing me as much as how to go about invoking the function from a web app Mar 14, 2018 at 17:12
  • The web3.js API was exactly what I was looking for, thanks so much man! :) Mar 19, 2018 at 13:03
  • @ColinFausnaught were able to create ERC20 token faucet, if so, can you send me some test ERC20 tokens on Rinkeby network? my address is 0x7EAA02f15Aaba8cb163F058ea506d702eB488E49 Any ERC20 token is ok, I want to then test it sending tokens from one addres to another, I will need ABI of the erc20 token too. thanks in advance Jul 20, 2018 at 7:26
  • Update, I've since learned that most ERC20's need to build faucet functionality into the contract of the token itself and have seen much better results doing that. So, rather than making a new contract to drip it's usually better to just build it into the token itself (saves gas too). Sep 12, 2019 at 16:37

Your Answer

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

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