How to develop Ethereum Smart Contract - part 1steemCreated with Sketch.

in #ethereum7 years ago

source: cryptocreed.com

Basic Solidity Smart Contract

[Notice: This Guide is only for Dummies, Not for Pro so if you are a PRO Kindly close this before You start Laughing and wasting your Time]

Hia!

First of all I am not a Teacher or professional so my way of stating a fact or theory will not be conventional. I am an amateur and I believe that best way to learn with fun is to lear with the amateur because he might give some hilarious examples which you can remember throughout the life on the that is why I always prefer to learn from books with titles Java for dummies, C# for dummies...etc., because they states the fact in very amusing way. I don’t want to bore you guys so let’s get started into this Solidity for Dummies.

1.1 First Things First
We are beginner so we will make mistakes but if we start making mistake on main ethereum blockchain then each mistake or erroneous deployment will cost us some ether. So to make mistakes and not lose any money we will use Test net ( Ropsten ), the more we make mistake the more and better the dummies will learn.

Before that also we need to have a chrome browser. Go to Chrome and download Metamask. After Installing Metamask > Click on the right menu bar on Metamask symbol > Configure everything like Password etc. > Click on the drop down menu on the Metamask window and select the Ropsten Network.

Now as you have not set up the Metamask in Test Mode with Ropsten Test Net let’s get some Dummy ether to get kick start.

After you have set up the Metamask account, click on Buy button and then it will take you to the Faucet, where you can claim some free ether for testing on test net.

No you have Test net and some Ethers to put your steps into Solidity world where smart contract will be deployed. After we have deployed the First smart contract we will verify it.

Remember in Altcoin section when devs create a smart contract and it is not verified then people start to chant scam, scam stuffs. :P

Things we will do NOW

  1. First we will Make the most simple smart contract that we can make.
  2. Deploy it on Test Net.
  3. Verify it to make look more credible.
  4. Then we will deploy it on Main Net, Yeah baby. [ Same steps as step 2 ]
  5. Then we will verify it on the main net. [ Same steps as step 3 ]

To get into code we should know where to code, I mean you can even code on NOTE PADor Sublime Text Editor or any Crazy Editor you like, But if you code in the program friendly code editor then most of the codes will come as suggestions in the form of dropdown as you keep typing, We are dummies though but not Dumb so we will not waste time in Notepad, even we are much conscious about our data pack and don’t want to download any software so we will use the Online Solidity Remixer.

After Opening the solidity remixer < Delete everything written in right hand side, and now paste the given below code, don’t worry I will explain you each and every single line of code.

Explanation of Code:

Above smart contract is just a simple contract to store a value to variable dummyData.

Line 1 simply says that the solidity version is 0.4.4 and Pragma stands same like #define in C++, basically it imports the basic rules for solidity, and in more simple term it is a preprocessor which is importing the rules from solidity 0.4.4 standard.

Line 2 : Now as we are making a contract so we say the compiler that we want to make contract followed by any name, here I have kept my contract name as DummyContract, you can chose anything you want.

DummyData is a state variable and uint (Unsigned Integer) is its type.

In Solidity smart contract is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Notice the difference here we talk about the state not just the variable itself.

Now as we have made a state variable dummyData now it is stored in DummyContract, fromhere now we can alter or call the state data by some functions called get and set.

Line 6 and 7: line 6 declares a function set and line 7 assign some value x to it.

Line 10 and 11: In line 10 tell we call function get and in line 11 we return the value of x to the function.

Now we have written our first smart contract, let’s get publish it on test net.
Go to left hand side on remix and select the setting tab. Now follow as said in figure.

Select the compiler version, don’t select the nightly ones.

Uncheck enable optimization checkbox.

Go to run tab and click Create button.

Now a Metamask Window will pop out, click on Create Button on it, Hold on now you Just created your First contract on Test Net, congratulations!
After 12 Seconds click on Metamask on the top of chrome again, Now you will see the contract published in it.

Now click on the date of contract in Metamask only. It will now open a new tab with the
contract and transaction, like given below figure.

Now after clicking the contract address new tab will open and in that click on contract
code< Verify the contract.

  1. Now enter the contract Name DummyContract
  2. Select the compiler version that we selected previously while coding.
  3. Disable the Enable Optimization to no.
  4. Now in the below code space paste the code from solidity remix to it.
  5. Click on verify.

If you had done everything correctly then you should get the contact verified now with a success message.

If you got any error while verifying then kindly pay the attention to every step minutely. Thus you have deployed your first smart contract on Ethereum test net, now repeat the same process by selecting the Main Net in Metamask and you will be done.

If you liked what I have taught then you can donate me some ether, I have tried to express everything in simple dummy language but still I am also a dummy.

For any query comment here: https://bitcointalk.org/index.php?topic=2407644.0

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62763.51
ETH 2579.20
USDT 1.00
SBD 2.72