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!
Best Answer
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.
To call that contract from a webapp using web3 v1.0 something like this should work
The contract will deposit a few tokens to "address".