Overview

Generally speaking, we think of a smart contract as a collection of functions that share and manipulate the same storage. At closer look, it is actually a special type of account and has therefore an address. It always starts with the letters KT1 and is also called originated account. This name comes from how it is created, by originating it from an implicit account. It is essential to understand that a program code is attached to it, written in the Tezos specific language Michelson. To start or invoke the code, the account needs to receive a transaction. Next to the cryptocurrency ꜩ, the transaction can also carry additional parameters. How the parameters find their way to the function is explained in more detail in the entrypoints article.

The notarization workshop provides a lot of theoretical background in why and how smart contracts can revolutionize fundamental processes of our modern society. Technically speaking, a smart contract is a decentalized code that can't be altered or stopped. The important aspect is that not only its storage, but also execution is decentralized and verifiable by the public. This makes the program code practically tamperproof.

graph TD account["Implicit Account<br>tz1...<br>tz2...<br>tz3..."]-->|sends|operation["Operation"] account-->|owns|tez["ꜩ"] smart-->|owns|tez operation-->more["..."] operation-->transaction["Transaction"] transaction-->|contains|parameter transaction-->|invokes|michelson["Michelson code"] transaction-->|sends|tez michelson-->|defines|storage operation-->origination["Origination"] origination-->|creates|smart["Originated Account<br>(Smart Contract)<br>KT1..."] smart-->|has|storage smart-->|has|michelson michelson-->|defines|parameter transaction-->|targets|smart account-->|manages|smart class account,smart nodeWarning class tez nodeTezos class michelson,parameter,storage nodeDanger click michelson,parameter,storage "/docs/knowledge/smart_contract/michelson" click operation,transaction,origination,more "/docs/knowledge/tezos_protocol/operations/operations" click account "/docs/knowledge/tezos_protocol/account"
Chef's tip 👨‍🍳

You can interact with the diagram by clicking on the node. It will take you to the relevant article.

Example contract declining incoming ꜩ

Smart contract code opens up almost endless possibilties in customizing the behaviour of an originated account. In this example, the program code is not supposed to handle cryptocurrency and therefore can't process receiving ꜩ. That's why it is best practice for you to implement a security mechanism that blocks the transfer of ꜩ to your contract.

Curious how easy it is too implement this logic? Below we can see the solution written in the high-level language ReasonLIGO. This code gets compiled to the lower-level language Michelson, which can be processed by the Tezos blockchain. Despite being bytecode, it is human readable, which sets it apart from other blockchain environments. After deploying this code to an originated account, you have customized the behavior of the account and it will automatically decline transactions carrying any ꜩ.

type parameter = unit;
type storage = unit;
let main = ((action, store): (parameter, storage)) : (list (operation), storage) => {
// Check forin the transaction that also contains the parameter
if (Tezos.amount > 0tez) {
(failwith("This contract does not accept tokens."): (list (operation), storage)); }
else {
// here goes the business logic of the smart contract
(([] : list (operation)), store); };
};