My first smart contract: good idea or bad logic?

crackthecodecrackthecode Member Posts: 8
Hello everyone,

Upon hearing about the Ethereum craze, I became more interested in the technology rather than the currency. In short, I have been trying to teach myself Solidity and so far that has been going pretty well. I have created my first (although stupidly simple) test-net smart contract called Wallet Faucet. Basically, it is a sort of decentralized faucet that runs on the blockchain, users can either donate or take a set amount of ether out. This is so they don't have to mine it and can start writing contracts without mining (or just get some quick test ether!). My question is, is this a good use of a smart contract? Or am I just not understanding the uses/technology properly? Thank you!
Post edited by crackthecode on

Comments

  • qqwyqqwy Member Posts: 15
    Yes, this is a perfect use!

    A Smart Contract could allow anyone to deposit Ether, and then allow people to withdraw a small amount of that Ether, but only if they (their address) haven't done so already during the past, say, hour.

    This is a great idea for learning how to write a smart contract yourself. If you want someone to look it over once you're mostly done, feel free to ask me, or post it here!
  • crackthecodecrackthecode Member Posts: 8
    edited July 17
    qqwy said:

    Yes, this is a perfect use!

    A Smart Contract could allow anyone to deposit Ether, and then allow people to withdraw a small amount of that Ether, but only if they (their address) haven't done so already during the past, say, hour.

    This is a great idea for learning how to write a smart contract yourself. If you want someone to look it over once you're mostly done, feel free to ask me, or post it here!

    Thank you! I have the contract able to allow users to donate to the faucet, and for someone to withdraw one ether, but I am not sure how to set a timer. Would I have to set the contract to run at a later block for that address? Thank you so much!
  • crackthecodecrackthecode Member Posts: 8
    edited July 17
    Here is what I have so far, keep in mind I am very new to programming :). I added a withdraw all function, but I would like to be able to refund ether to all the donators. Is that possible? :
    pragma solidity ^0.4.0;
    
    contract WalletFaucet {
      
      address owner;
      bool _switch;
      
      event infoUpdate(string update, uint money, address _address);
    
      function WalletFaucet() {
          owner = msg.sender;
      }
      
      modifier onlyOwner() {
        if (msg.sender != owner) throw;
        _;
    }
      
     
      //users will be able to donate as much as they like.
      function donateEther() payable {
        infoUpdate("User donated: ", msg.value, msg.sender);
      }
      //A function that allows a user to withdraw a set amount of ether.
      function withdraw1Ether(address _address_ToSend) {
        //only allows 1 ETHER.
        uint paymentAmount = 1000000000000000000;
        
        if(this.balance < paymentAmount) {
           revert();
        }
        
        if(_address_ToSend.send(paymentAmount)) {
            _switch = true;
        }
        else {
            _switch = false;
        }
    
        infoUpdate("User received: ", paymentAmount, _address_ToSend);
      }
      
      function withDrawAll() onlyOwner() {
          uint totalFunds = this.balance;
          owner.send(totalFunds);
          
      }
      //gets total funds in faucet.
      function getTotalFunds() constant returns(uint){
        return this.balance;
      }
    }
Sign In or Register to comment.