Programming in Ethereum - My First Contract (Part 1)

in #ethereum7 years ago (edited)

Hello,

I do not like long introductions. I'm from Poland. I'm computer programer very interested in programming Ethereum Smart Contracts. I've registered here because I want to see how Steemit works, because from what Ive heard It's really cool.

_DSC6157_m-4.jpg

I want to show how easy programming on Ethereum can be.

So Let's Start!

What do You need for programming on Ethereum Blockchain?

Well...........Chrome Browser. and thats it!.

What can You use Ethereum Blockchain For?

Everything, anything. Ethereum is Turing complete what means any alghoritm can be runned on it.

How to start

  1. Download and install Chrome
  2. Install Metamask Plugin
  3. Configure Metamsk like in this movie
  4. Go to Rinkeby Ether Fucet to get some test ether
  5. Go to Remix IDE and start coding!

Ok, but what we can we code?

Let's start with something simple but usefull

Let say You and Your friend work on the website together and You want to recive donations in ether and split it 60% to You (you also need to maitain a server so it is more work to do!) and 40% to Your friend (he participate in creating a content)

Your address is
0x59A5aC4033dB403587e8BEAb8996EDe2F170413a
And your friend
0xAF97e87375d97F45b1C5F4ea4cC87650f640581F

Doing an Exercise change addresses to two You own (or Your and Your friend!)

You want to create contract address that sends 60% of any transfer to You and 40% to Your friend

Code looks like that:

contract EthSpliter {
address YourAddress = address(0x59A5aC4033dB403587e8BEAb8996EDe2F170413a);
address YourFriendAddress = address(0xAF97e87375d97F45b1C5F4ea4cC87650f640581F);

function () public payable{
    YourAddress.transfer(msg.value*60/100);
    YourFriendAddress.transfer(msg.value*40/100);
}

}

First let us look how to deploy that contract

Remember Remix IDE? Go there and paste that code instead of what it is there now

Now Click >>Start to Compile<<

And go to Run Tab

Choose in environment >>Injected Web3<<

if You installed Metamask properly and You are logged in with Rinkeby Test Net (Left upper corner of Metamask window)
You should see Your Account address and some ether as a balance

Click Red Button >>Create<<
Remix.png
now in the bottom window you should see " creation of browser/ballot.sol:EthSpliter pending..."
when the transaction is finished You will se some more lines popping out and also
contract with address on the right

See >>(fallback)<< button?

You can click it, but first set >>Value<< To 1 - that will cause to send 1 Eth to the contract

Metamask will Pop-up
Metamas.png
confirm transaction.

You can click Metamask icon and then a line with transaction - it will redirect You to Etherscan Page with transaction.

When Transaction is Finished You will see that 0.6 Eth went from sender address to YourAddress You set in a contract and 0.4 Eth Went to YourFriendAddress .

This app will be work forever ! Easy ?

In Part II I will Explain differrent Parts of code and Give some more hints about tools.

Please Comment, what You want to see, how to improve this posts, what was unclear?. Any advices appreciated!

Cheers

Sort:  

I like your post. You say its really easy to start in Etherium, but a lot of people are complaining that you have to install a ton of stuff. What do you think of the "Etherium Killers" - EOS,NEO,QTUM from the perspective of a programmer? Good info, keep them coming :)

Thank You for comment
Eos might be interesting alternative soon, I like NEO tooling, But it will be hard for them to catch up You need to remember that security of the network is directly connected to hashpower which is connected to market cap. So it will be hard for others to catch up, especially taking under consideration that Ethereum team also do not sleep. But time will show :)

As You see from my post You do not need install anything to start, of course
If You go to more advance scenarios then things like :

truffle framework
testrpc

comes into play, but You do not need them to start. You do not need them for quite a long time to learn.

Welcome to Steem @jinx1984 I have upvoted and sent you a tip

Welcome. I started learning some basics of solidity. Will be interesting to read your upcoming posts. Will follow you :)

Hi,
tell me if my post was clear to You, I hope I will be helpful.

welcome to the magic that is steemit!

Nice into and first post :)

You have another follower

Nice to hear it.