November 20, 2026

Capitalizations Index – B ∞/21M

Create your first smart contract on the Ethereum Blockchain: Fundraising Contract

Create your first smart contract on the Ethereum Blockchain: Fundraising Contract

It is almost inevitable to escape the term cryptocurrency in today’s world. If you have crawled upon this post, then it is probably certain that you understand that there is more to the Blockchain then cryptocurrencies.

To completely understand this tutorial, it is important to understand what a blockchain even is. If you are already familiar with the topic, feel free to skip ahead, otherwise, I would recommend a quick read here.

Dapps (Decentralized applications) are applications that communicate with the blockchain via “Smart contracts”, typically with a javascript/html frontend living on a centralized server, and a smart contract living in the blockchain. This post will only go over the backend side (smart contract). (Complete Dapp Tutorial coming later)

As this post is not dedicated to general programming, I will not go into details on the programming syntax and logic, however, it is important to know that the only programming language on the Ethereum blockchain with smart contracts is “Solidity”. You can find the docs and more information regarding “Solidity” here.

Ready to start?!
Navigate to remix.ethereum.org which is a web-based solidity compiler which allows us to write and test our smart contracts. You should see something like this:

The first thing we need to do is define which version of solidity we will be using. Type this in at the top of the editor to define the version.

pragma solidity 0.5.6;

Our contract will be called “DappFrundraiser”. All of the code that exists in this contract must live within the two brackets. Also, include an empty constructor which we will use in the next block.

contract DappFundraiser 
}

So what exactly is our contract going to do?

Variables:
– owner : who is the contract admin (who deployed it)
– contributers: who has contributed to the fundraiser 
– contriubterAmount: the amount a user has contributed
– miniumContribution: the least amount somebody can contribute
– fundingGoal: how much funding does the contract need/want to raise

Functions:
– contribute() : contribute to the campaign
– getContributionBalance(): see how much funds have been added to the fundraiser from contributors

Now we can add our variables into the contract using the following syntax:

//  address of admin - the one who deployed the contract
address owner;
// addresses of contributers
address[] public contributers;
// address of contributer - also allowing us to see how much was contributed
mapping(address => uint) public contributerAmount;

// minimum amount a user can contribute to the fundraiser
uint public minimumContribution;

//amount of funding needed before contract has reached its goal
uint public fundingGoal;

Solidity comes with a global variable called msg. We will use the following in this contract:
msg.sender (address): sender of the message (current call)
msg.value (uint): number of wei sent with the message

When deploying the contract, the constructor will be called one time, and one time only. This is the perfect opportunity to set the owner (admin), minimum contribution amount, as well as the funding goal for the contract.

pragma solidity 0.5.6;
contract DappFundraiser 
}

Now let’s create the function that allows us to check to contract Ehter balance. This is important because user funds should not be taken if the fundraising goal has already been met! This will act as a helper function in our contract.

function getContributionBalance() external view returns(uint) 

Ok now we are down to the last function before we deploy and test our first smart contract! The last but most import function “contribute()” is responsible for collecting the funds from users, while making sure this rule applies:
* The contribution payment must meet the minimum contribution fund we set in the constructor.

function contribute() external payable 
}

When we put it all together, your contract should look like this:

pragma solidity 0.5.6;
contract DappFundraiser 

function getContributionBalance() external view returns(uint)

function contribute() external payable
}
}

Now it is time to compile our smart contract and test it out. To do this, select the 0.5.6 compiler on the top right side and then click “compile”. If all goes as planned, you should see a green box on the middle of the screen on the right side with the contract name. See screenshot below:

Before doing anything, change your environment to the Javascript VM (see image below)
To deploy the contract, you must enter in the two parameters we included in our constructor (minimumcontribution, and fundingGoal). After these two parameters have been entered in the deploy section, press “transact”. You just deployed your first contract!

You should now see a tab under with the contract name “DappFundraiser”. Click the arrow on the left side to open up the contract functions. You will notice that some of the functions are labeled pink, while others are blue. This goes into a much deeper topic in the blockchain involving gas fees. The pink labeled functions are functions that require the blockchain transaction chains to be changed (mining) which require a small transaction fee. To learn more about this, please click here.

To change wallets (users — each wallet belongs to one user, unless of course one user has multiple ethereum wallets), navigate through the accounts dropdown.

When testing the contribute() function, make sure to add the minimum payment in the value section. This is imitating sending (x) amount of ether as a contribution. It is set at 0 every time you click a new function, so make sure to always re-enter the minimum contribution value or more when testing the contribute function :).

Congrats! 
You have just written your very first smart contract. This was just a quick tutorial on how to get started with contracts, however, if you are interested and you would like to learn more, you can always use this contract as a base and add a few more functions to it. A few ideas..
1) Add an end date to the fundraising project
2) Refund users if the goal was not met before the contract deadline
3) Destroy contract upon completion
4) Connect smart contract to a javacsript/html web app and build your first Dapp!

Thanks for reading my post! If you have any questions or comments, I would love to hear from you!
Best regards

Published at Wed, 24 Apr 2019 20:35:44 +0000

Previous Article

Bitcoin [BTC] fraudster becomes ‘one of the first people in the US to be convicted of stealing cryptocurrency’ |

Next Article

Bitcoin Core 0.17.1 Released

You might be interested in …

Understanding proof of work: bitcoin’s secure consensus mechanism

Understanding Proof of Work: Bitcoin’s Secure Consensus Mechanism

Understanding the Computational Foundation of⁤ Proof⁢ of Work the computational foundation of Proof of Work (PoW) lies in solving complex cryptographic puzzles that require critically important processing power.This ‍mechanism ensures that ‌network participants expend real-world […]

Venezuelan Senate Outlaws the Creation of the Petro Cryptocurrency

Most people are well aware of how Venezuela wants to create its own cryptocurrency. Known as the Petro, this new form of money is backed by the country’s natural oil reserves. Although president Maduro has planned to issue quite a few of these coins in the near future, that may not happen after all. More specifically, the Venezuelan Congress outlawed the Petro cryptocurrency altogether. In their opinion, this new currency is an “effort to illegally mortgage the country’s oil reserves”.

Venezuela is a country on the verge of collapsing financially. A lot of problems have arisen in recent years and the situation only grows direr. Coming up with a solution to these problems has not been easy. President Maduro has experimented with a few different solutions, but not made any real progress. Instead, he wants to resort to creating a national cryptocurrency, known as the Petro. Backing the value of this currency are Venezuela’s natural oil reserves.

What Will Happen to Venezuela’s Petro?

On paper, this concept makes a lot of sense. It would provide some financial relief for the struggling nation in the coming months and years. Unfortunately, Venezuela’s government isn’t too keen on this idea whatsoever. In fact, they outlawed this cryptocurrency from being created and issued altogether. A remarkable turn of events, although such a move was to be expected at some point. The opposition-run parliament feels President Maduro wants to illegally mortgage the country’s oil reserves. Some very harsh language is being used to make this point even more apparent.

Issuing the $6bn worth of Petro will not happen anytime soon due to this decision. Venezuela needs hard currency and evade financial sanctions at the same time. Without this cryptocurrency, that may become an insurmountable challenge. At the same time, financial experts tear this currency will lead to even more financial mismanagement by the government. The big question is whether or not investors are even interested in the Petro at this stage. Right now, that doesn’t appear to be the case, but things can always change in the future.

For the time being, it remains to be seen how this situation will evolve. It is evident Venezuela’s economy is crumbling as we speak. This situation has gone from bad to worse in quick succession. A national cryptocurrency may very well be the country’s last resort. Unless the Senate reverses its decision, that currency will never exist in an official capacity. This is a very interesting situation well worth keeping an eye on. After all, the Petro may set an international precedent in more ways than one.

Header image courtesy of Shutterstock

The post Venezuelan Senate Outlaws the Creation of the Petro Cryptocurrency appeared first on NewsBTC.