14 ms·
Understanding Ethereum Smart Contracts
- huhtenberg 9y agoAny other "gentle introductions" out there? Something with a complete walk-through both from contract creator's perspective and from some random node on the network. This one failed to explain how contract calls are executed - is it by a single node, by multiple nodes, do nodes compete with each other for the execution, what's their incentive, etc.
- benchaney 9y agoI don't have a better article, but I can try to answer your question. Ethereum contracts are executed everywhere that the blockchain is downloaded and verified. They are deterministic, so every execution should return the same result.
- tmlee 9y agoContract calls are executed by all the nodes in the network. And they will all update the contract state onto their own blockchain then broadcast the result and compete via proof of work.
- posedge 9y agoI wonder how they can ever expect a system like this to scale given that every node has to execute every instruction in every called smart contract...
- gibybo 9y agoScaling is definitely a serious concern and is a large focus of Ethereum developers at the moment. I don't understand much about the proposed solutions, but they generally think the Ethereum network can be sharded in a way that allows only a small subset of the network to run any given contract and still guarantee reliability similar to as if the whole network had run it.
- jacquesm 9y agoYou'll need some very hard guarantees that that 'small subset' can never be under the control of a single entity.
- DennisP 9y agoThat's a good point. Bear in mind though that each subset can be larger than today's entire Ethereum or Bitcoin network.
- zodiac 9y agoIt doesn't work like that - a working sharding scheme should not fail if one shard is taken over. This is the most recent description of ethereum sharding if you want to learn more -> https://youtu.be/9RtSod8EXn4?t=3h12m30s https://youtu.be/9RtSod8EXn4?t=3h12m30s . In particular look at step 4 where the fork choice rule is changed so that shards with invalid blocks cannot exist on a valid base chain.
- DennisP 9y agoAlso various more specialized schemes to run things offchain, and submit to the chain only the results and some kind of assurance that you ran them correctly. (E.g. Raiden, Plasma, TrueBit)
- alx 9y agohttp://decypher.tv/series/ethereum-development http://decypher.tv/series/ethereum-development
- albertgoeswoof 9y agoI like to think of Ethereum as a giant virtual machine that shares it's CPU (contracts are the instructions) and Storage (the ethereum blockchain) across all nodes that participate. Every node re-runs everything locally to validate and move the state of the machine forward. And of course you get paid to do that through mining. When you view it like that it's obviously very costly to execute code & store outputs, so alternative solutions are needed for lower value code. Breakthroughs in these areas could make Ethereum a viable platform for computing, and it honestly feels like we could be entering a new computing paradigm with it.
- jashmenn 9y agoYes, I have a free intro to writing DApps with Ethereum course over here: https://www.newline.co/ https://www.newline.co/ Contract calls are executed by every node on the network -- if you've heard of "embarrassingly parallel", Ethereum is "embarrassingly serial". That is, every function call, on every contract, is run by every (full) node on the network. The calls are deterministic which means that the nodes can verify that their peers calculated the outcome correctly and didn't try to cheat. It sounds expensive (and it is) but that's the (current) cost of decentralized, trustless computation.
- jklepatch 9y agoI hav started a youtube channel to teach ethereum and solidity: https://m.youtube.com/channel/UCZM8XQjNOyG2ElPpEUtNasA https://m.youtube.com/channel/UCZM8XQjNOyG2ElPpEUtNasA Contract call can be broken down into 2 categories: state changing vs read-only. If its a state changing contract call, it will be executed by every node on the network. In this case its considered a transaction. This transaction has to be mined in a block and cost ether. The new state will be stored on the blockchain only after the transaction has been succesfully mined. The other kind of method call is read-only. Its free, ,is executed only by a single node, and does not alter the blockchain state.
- lowglow 9y agoWe had an SF crypto builders meet-up[0] where I gave a talk on Introduction to Solidity programming[1]. It's a pretty good primer to get from zero to smart contract in about 30 minutes. Learn from my suffering. [0] https://www.meetup.com/sfhackdays/ https://www.meetup.com/sfhackdays/ [1] https://www.facebook.com/hackdays4all/videos/544008492611485/ https://www.facebook.com/hackdays4all/videos/544008492611485...
- j_s 9y agoJust over a month ago, HN user DennisP answered the question "How did you get into contract ethereum development?". https://news.ycombinator.com/item?id=15496393 https://news.ycombinator.com/item?id=15496393 If you are starting back at the idea of the Bitcoin blockchain, see ahussain's recommendation of 3Blue1Brown a day later: https://news.ycombinator.com/item?id=15504409 https://news.ycombinator.com/item?id=15504409 https://www.youtube.com/watch?v=bBC-nXj3Ng4 https://www.youtube.com/watch?v=bBC-nXj3Ng4
- scandox 9y agoWhat I'd greatly appreciate is a walk through of a plausible real world use case. I find it hard to concentrate on the technology itself until I understand the application.
- decentralised 9y agoCrowdfunding (ICOs) is a use case. DNS (ENS) is a use case. Organisational Transparency (Aragon) is a use case. Prediction Markets(Augur) are a use case. Electricity Markets (Grid+) are a use case. International payment card with zero fees (TenX) is a use case. I can go on for a while longer, there are hundreds of use cases but the question is: what would be a use case for you?
- scandox 9y agoThey all sound great. So what I'd love to see is a well written blog post describing how Ethereum would be put to work to achieve one of those goals and to give me an understanding of its superiority within the domain. I'm not demanding it and I'm not being snarky at all. It's just that's the level I'm at - without that kind of entry point I struggle to assess it.
- _red 9y agoSome of the use cases can be fairly simple (thus easier to see the value). 1. Me and You start a company together. We would like to split things 50/50. We setup an address such that when values are paid to it, half goes to you, half goes to me. Effectively we've created an "LLC with an Operating Agreement", but we aren't relying on political legal system / country to enforce. Enforcement is automatic and done by the network. 2. You want to setup a Trust for your kids. You create a contract that holds 10 Bitcoin / Etherum / etc. On the date Jan 1, 2035 the value of that address will be forwarded to your child's address. Again, we created a "Non-Revokable Trust" that is network enforced. No need for probate, courts, trustees, etc.
- scandox 9y ago
- dsr_ 9y agoI am particularly amused that in the first example, a simple counter, no mention is made of the initialization routine being callable at any point... at which time the counter is reset to zero.
- decentralised 9y agoThe constructor function is only called on deployment so the counter will increase with each new call.
- alvarosevilla95 9y agoIf I'm not mistaken in Solidity constructors can only be called once on a contract
- cratering 9y agoYes that is correct http://solidity.readthedocs.io/en/develop/contracts.html#creating-contracts http://solidity.readthedocs.io/en/develop/contracts.html#cre...
- cygned 9y agoI really recommend reading the whitepaper. It not only explains Ethereum very well, it also contains the best explanation of Bitcoin I have ever read. https://github.com/ethereum/wiki/wiki/White-Paper https://github.com/ethereum/wiki/wiki/White-Paper
- jatsign 9y agoI've been programing my own Ethereum smart contract (virtual currency) for awhile now. Here's some gotchas off the top of my head: - You have about 500 lines of code to work with. This of course varies, but smart contracts have to be really small to fit in the max gas limit (6.7 million wei). - You can't pass strings between contracts (coming soon). - There are no floating point numbers. Since you're probably working with "money", this can make things tricky. - You can break up your code into multiple contracts, but the tradeoff is an increased attack area. - Dumb code is more secure than smart code. - The tooling is very immature. You'll probably use truffle, which just released version 4. It makes some things easier, some harder. It's version of web3 (1.0) may differ from what you were expecting (0.2). - The Ethereum testnet (Ropsten) has a different gas limit than the main net (4.7 million vs 6.7 million).
- flashmob 9y agoSome very good points. I recall that the mainnet once had a gas per block limit of 4.7 mil before it was increased. The increase is something that is voted on by the miners, and has been fluid over the years. (Btw, it is something very similar to a block size limit in BTC, although it limits the storage + CPU usage, rather than just storage like in BTC) About the point on using floats, one should never use floats when working with money, this is because floats are not precise and result in rounding errors (eg. 0.1 + 0.2 results 0.30000000000000004, see for details http://0.30000000000000004.com http://0.30000000000000004.com ). One of the simplest approaches to solve it is to work with the smallest units, so if working with dollars then you can use cents and that means you can use integers which give more precision, which is how Solidity currently deals with it, by working with the smallest unit of Ether which is 'wei'. Some of the units listed here https://etherconverter.online https://etherconverter.online
- workmandan 9y agoDang you got there 3 minutes before me!
- Slartie 9y ago
- julioademar 9y agoI published a code walkthrough tutorial yesterday on this: https://hackernoon.com/full-stack-smart-contract-development-fccdfe5176ce https://hackernoon.com/full-stack-smart-contract-development...
- maxencecornet 9y agoI was looking for something like this Thanks !
- coryl 9y agoI've also just begun to play with smart contract programming. One problem I'm having is with event listening. It seems that MetaMask doesn't yet support subscriptions, nor does my localhost testRPC instance pass it in the web3 object. Some have suggested I need to run my own node just to listen for contract events. Has anyone figured out an easier solution?
- jatsign 9y agoI've had success listening to events using web3, against both testrpc and geth (on private and test networks). What version of web3 & testrpc are you using?
- coryl 9y agoI'm using web3 1.0.0-beta.26, ganache-cli 6.0.3 I instantiate the web3 object as such: web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); http://localhost:8545")); When I try to setup an event listener, console logs this: Error: The current provider doesn't support subscriptions: HttpProvider
- brepl 9y agoPossibly because the latest version of MetaMask has broken event listening: https://github.com/MetaMask/metamask-extension/issues/2393 https://github.com/MetaMask/metamask-extension/issues/2393
- fokinsean 9y agoQuick question, do you have to download the full ethereum chain before you can start messing with smart contracts? Or is there a "light" client you can use?
- fortenforge 9y ago> Bitcoin transactions are pretty simple in what they do. You can do one single thing. One type of transaction. Skipping some details, it all boils down to TO (who is receiving money), FROM (who is sending money) and AMOUNT (how much money). This let’s bitcoin be a store of value with the capability to transfer the value between participants in the network. Doesn't Bitcoin script allow you to do far more complex things than just send btc from person A to person B?
- stuxnet79 9y agoYes it does. A lot of people tend to brush over this aspect of BTC. The whole notion of smart contracts is really just an extension of the scripting capability introduced in BTC which some felt was far too limited.
- runeks 9y agoNot only that, but Bitcoin script was intentionally designed to be Turing incomplete, in order to allow static analysis of time/space complexity. Ethereum was invented to fill the space of a blockchain with a Turing-complete scripting language, which may or may not prove to be useful in the real world (in my opinion it hasn’t yet).
- bjaanes 9y agoYes, technically true. You can do some stuff there, but it is somewhat limited. I said I was simplifying some details, this is one of them. It only adds to the confusion. I don't think many people use it. At least not for any really complex use cases (I may be wrong, but that is the extent of my knowledge). Looking at this I don't see how it can do too much interesting stuff: https://en.bitcoin.it/wiki/Script https://en.bitcoin.it/wiki/Script
- deleted 9y ago[deleted]
- mvkel 9y agoDoes this fundamentally break down if the cost of ETH rises to a level where it’s too expensive to run code on the chain?