This video is available to students only

What is a Smart Contract?

What is a smart contract? It's like a regular contract, but defined by code (and in Ethereum with Solidity, a smart contract is essentially an instance of a class).

Smart Contracts

What is a "smart contract"?

Answer: it's like a regular contract, but defined by code.

But let's take a step back, what is a "contract" anyway? Normally when we think of contracts we think of a written document where we sign on the bottom line. But the idea of a contract is a bit more general.

Fundamentally a contract is an agreement between two parties. And we agree on and participate in contracts all the time.

Maybe it's an agreement to buy a car and make payments to the lender every month. Or maybe we make an agreement with our library that we can borrow a book and we'll return it on time or face a fine of 10 cents per day.

Maybe it's an agreement to pay monthly for fire insurance and if our house burns down the insurance company will pay us a lump sum. Or maybe we have an implicit social contract with our friends that if we go to dinner, we'll all split the bill evenly.

Another place where contracts are used extensively are financial products.

Stocks are a good example of this. Owning a share of a business gives you certain shareholder's rights. You might receive a portion of business profits through dividends, have a right to information about the company's financials, or have voting rights, etc.

These rights are defined by a company's shareholders agreement, which themselves are shaped by the governing law in a particular jurisdiction. And even with that, enforcement of any particular clause depends on the decisions of the lawyers, lawmakers, and judges involved.

The idea with a smart contract is that we're totally defining the rules of our agreement in code.

We should look at some examples.

Nick Szabo, the inventor of Bit Gold, developed the concept of smart contracts. In his essay, titled "The Idea of Smart Contracts", he gives two examples: a vending machine, and a car loan with a twist.

Let's start with the Vending Machine

Vending Machine

You can think of a vending machine as a mechanical contract between a thirsty buyer and a beverage creator. 

The buyer puts in a certain amount of money, and the machine dispenses a drink and change, if necessary. There's even a rollback mechanism if the buyer requests a refund or the drink can't be delivered.

The vending machine acts as an escrow between the buyer and seller. And while the amount at stake is small, there is a moment when the machine controls both the drink and the funds.

The buyer and seller agree to this arrangement because there's an understanding that the machine will act according to its programming and treat both sides fairly.

 

This page is a preview of Intro to Programming Ethereum ĐApps

No discussions yet