Ethereum runs programs, and ether pays for them

You will be able to explain smart contracts, gas fees and staking on Ethereum.

Darren has worked out what bitcoin is. Then his friend Farah mentions that she holds ether, staked it for a yield, and paid a S$15 fee to swap one token for another. Darren assumes ether is a competing version of bitcoin. It is related, but it was built to do a different job, and that changes what you are holding when you own it.

A blockchain that runs programs

Bitcoin's ledger mainly records who sent how much to whom. Ethereum, launched in 2015, records payments too, and on top of that it can store small programs and run them, which people call smart contracts. The name oversells them a little, since there is no lawyer or court involved: a smart contract is code sitting at an address on the blockchain, and it does exactly what it was written to do whenever someone sends it a transaction.

That one change opens a lot of doors. A smart contract can hold tokens and release them when conditions are met. It can run an exchange where people swap tokens with each other without a company in the middle. It can issue a new token, or let people lend to each other at rates set by code. Most of the tokens you will meet in lesson 2.3, Tokens, DeFi and the questions to ask any of them, are smart contracts running on Ethereum or on blockchains that copied its design.

Every computer that keeps a copy of Ethereum has to run each program to check the result. That work is not free, so somebody has to pay for it.

Ether pays for the work, as gas

Ether, written ETH, is Ethereum's own coin, and inside the system its main job is paying fees. Every operation a transaction asks the network to do has a cost measured in units called gas. A plain transfer of ether from one address to another uses 21,000 gas under the protocol's rules. A swap through an exchange contract uses many times more, because the code does much more.

You pay for each unit of gas at a price quoted in gwei, which is a billionth of one ether. The price rises when the network is busy and falls when it is quiet. So the fee for a transaction is the gas it uses multiplied by the gas price.

Here is a worked example with a made-up gas price of 20 gwei. A plain transfer costs 21,000 times 20, which is 420,000 gwei, or 0.00042 ETH. A contract interaction using 150,000 gas at the same price costs 0.003 ETH, roughly seven times more. That is why Farah's token swap cost far more than a simple transfer would have, and why fees on Ethereum can jump when lots of people rush to use it at once.

The Merge: from mining to staking

Ethereum started out with proof of work, the same mining approach you met in lesson 1.2, Why proof of work makes the ledger hard to rewrite. In September 2022 it switched to a different method in an upgrade known as the Merge. Mining on Ethereum stopped, and the Ethereum Foundation reported a very large drop in the network's energy use as a result.

The replacement is proof of stake. Instead of spending electricity on a guessing puzzle, participants called validators lock up ether as a deposit. The protocol picks validators to propose and check new blocks, and pays them in ether for doing it honestly. A validator who breaks the rules, for example by signing two conflicting versions of a block, can have part of the deposit destroyed by the protocol, a penalty known as slashing, and may be removed from the validator set.

The security idea is the same as mining, with a different cost. In proof of work, an attacker has to outspend the honest miners on hardware and power. In proof of stake, an attacker has to control a large share of all the staked ether and risks losing it.

This is also where Farah's yield came from. Staking rewards are paid for helping secure the network. If she staked through an exchange or another service, though, she handed her ether to that company to stake on her behalf, and she now depends on that company as well as the protocol. Hold that thought until module 3, because MAS does not allow licensed exchanges to stake retail customers' tokens.

Code is only as safe as the people who wrote it

A smart contract follows its code to the letter, and the code sometimes allows things its authors never meant to allow. If there is a bug, anyone who spots it can use it, and because confirmed transactions cannot be reversed, there is often nobody to appeal to afterwards. Bugs and exploits in smart contracts have led to large losses over the years, sometimes in contracts that held the savings of many thousands of users.

Some projects pay outside firms to review their code before launch. A review lowers the risk but does not remove it, and many contracts are never reviewed at all. When a platform tells you your money sits in a smart contract, the real question is who wrote the code, who checked it, and whether anyone can change it after you deposit.

For Darren, this gives two separate things to judge. Ether's price depends on demand for the network and for ether itself, with no earnings behind it, much like bitcoin in lesson 1.3. The contracts he might use on Ethereum carry their own risk on top, which no change in the price of ether will fix.

The quickest way to see all of this is to look at a real transaction. On an Ethereum block explorer, a transaction page shows the gas used, the gas price, the total fee in ether, and whether the transaction went to an ordinary address or to a contract.

Look up one Ethereum transaction on a public explorer and note the gas fee paid and the contract it interacted with, if any.

Course

Junxiong-WFG Organisation is an authorised representative of AIA Financial Advisers Private Limited (Reg. No. 201715016G).