WinDeveloper Coin Tracker

  • Home
  • Ethereum
  • Getting Started with Solidity Programming for Ethereum

Getting Started with Solidity Programming for Ethereum

  • Published: Jul 14, 2020
  • Category: Ethereum, Solidity
  • Votes: 4.9 out of 5 - 7 Votes
Cast your Vote
Poor Excellent

There are ample resources out there to get started with smart contract development. Many go into detail in regards to how Blockchains work, and the ins and outs of Ethereum. This article is intended for those who are less patient and want to create a first smart contract now.

There are ample resources out there to get started with smart contract development. Many go into detail in regards to how Blockchains work, and the ins and outs of Ethereum. This article is intended for those who are less patient and want to create a first smart contract now.

We do advise you to read up on Blockchain, Smart Contract and Ethereum basics before you launch your smart contracts though. But, we're going to jump right in.

remix.ethereum.org

There are many IDEs and tools out there, but if you want to dive straight into Solidity without worrying about setting up an environment you can use: remix.ethereum.org

This article was written using Remix version 0.10.1. But, if a newer version has come out since most functionality should still be the same.

WARNING: Remix is an in-browser IDE which relies on your in-browser data. Make sure to keep copies of your code elsewhere if you use it as an IDE.

This is what you should see:

Initial remix screen

Set up Remix to use the Solidity environment:

Select Solidity environment

This will add on the following plugins to Remix which we’ll need to compile and test:

Solidity plugins added in remix

Remix provides a number of example smart contracts (listed in the file explorer) but we’ll just jump right in and create our own. Create a new smart contract by + button:

Add a new smart contract

Insert the smart contract File Name (Solidity smart contracts' file extension is .sol). In my case, I created "SharedPiggyBank.sol"

We’ll create a piggy bank which will allow for a parent of twins to deposit funds, or rather Ether (the cryptocurrency used in Ethereum), into a smart contract and will only allow for the twins to withdraw the Ether:

  1. 10 years after the smart contract was created; and
  2. provided that both twins want to ‘smash’ the piggy bank and get their 50% of the Ether

I’ll start by creating an empty Smart Contract to test out the environment. The code follows:

pragma solidity >=0.4.22 <0.7.0;
contract SharedPiggyBank {

}

The first line defines the solidity compiler version which this code will work for (in this case between 0.4.22 and 0.7.0).

Let’s make sure that the code is compiling and can be uploaded to the blockchain without any problems.

Click the Solidity Compiler button shown below:

Select the Solidity compiler

Now turn on the "Auto compile" feature, this will make sure that the code automatically compiles as we type it out:

Enable auto compilation

If the contract compiles you should see it listed in the Contract dropdown below the Compile button (in the Solidity Compiler tab):

The compiled smart contract

If there are any compiler errors though, they will appear below in the Solidity Compiler tab:

Make sure you do not have any errors before trying to deploy the Smart Contract.

Let's see that we can deploy the smart contract to the Blockchain. What we're doing now is deploying it to a simulated Ethereum network (inside the browser). This is great for testing as deploying to the Ethereum network would take more time and funds (if on Ethereum’s main network).

Click the Deploy and Run Transactions tab as below:

Click the Deploy and Run Transactions tab

Now, to upload the Smart Contract, press the "Deploy" button:

If successful, you should see that the contract has been deployed in the Deploy and Run Transactions tab:

The deployed smart contract

NOTE: When you deploy a smart contract it remains in Remix until you decide to remove the uploaded smart contract. Deploying the same smart contract twice it will create two different instances of the smart contract. So, it’s always best to remove your previously deployed smart contracts before deploying a newer version. (Also, smart contracts cannot be removed from the Ethereum live network).

You should also see a message in the console that highlights the successful deployment:

Successfully deployed log

Great, now we'll continue developing the smart contract in the next article to be uploaded soon!

Copyright 2024 All rights reserved. BlockchainThings.io