Giter Club home page Giter Club logo

ethereum-solidity's Introduction

Ethereum-Solidity

Smart contract in Solidity, using the Ethereum blockchain.

The smart contract's purpose is to facilitate donations to different charities. When a user wants to send some funds to a destination address, instead of sending them directly to that address, they will use the smart contract. A part of the funds will be sent to the charity the user specified, while the rest will go to the destination address.

This is a code of a contract that when deployed, will accept a list of charities at creation time, specified by their respective addresses. For facilitating the transfer of funds, the code has two different variations of the same method. The users that would want to donate, will then make their payments by sending funds to these methods.

In the first variation, the method that facilitates the payments, will accept a destination address, as well as the index number of the charity (0 is the index for the first charity, 1 for the second etc). The method redirects 10% of the funds to the selected charity, while transferring the rest to the destination address. The contract makes appropriate checks if the user that originated the transfer has sufficient funds and if the charity index number that is provided is a valid one. In the second variation, the method additionally accepts a value for the donated amount (in wei). In addition to the checks that the previous variation performs, in this case, also checks that the donated amount is within acceptable limits; a donation has to be at least 1% of the total transferred amount, while it cannot exceed half of the total transferred amount.

The contract keeps track of the total amount raised by all donations (in wei) and towards any charity, collectively, and provides means for any interested party to access that information. So, for example, if one donation of 2 ether has been made to charity A and another donation of 3 ether was made to charity B, the contract reports that 5 ether was donated in total. The contract, also, keeps track of who is the person that made the highest donation, identified by their address, along with the amount they donated. This information is available with a single call to one method in the contract. It is also available only to the user that deployed the contract. When a donation has been made through the contract, an event transmitting the address of the donor and the amount donated, is emitted. It also provides some means to destroy the contract and render it unusable. This functionality should be available only to the user that deployed the contract.

Notes:
● Uses method overloading for providing two different variations of the same method that facilitates the transfer of funds.
● Uses a modifier to restrict access to functionality.
● The addresses of the charities are not publicly available.

  1. The contract was compiled in Remix - Ethereum IDE
  2. Addresses were created using Ganache - Truffle Suite

ethereum-solidity's People

Contributors

sophiavei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.