Deploy a smart contract with SmartPy
This tutorial covers writing and deploying a simple smart contract with the SmartPy programming language. SmartPy has syntax similar to Python, but you don't need any experience with Python or SmartPy to do this tutorial.
- If you are more familiar with OCaml, try Deploy a smart contract with CameLIGO.
- If you are more familiar with JavaScript, try Deploy a smart contract with jsLIGO.
- To learn the Archetype language, try Deploy a smart contract with Archetype.
SmartPy is a high-level programming language that you can use to write smart contracts for the Tezos blockchain.
It abstracts away the complexity of using Michelson (the smart contract language directly available on-chain) and provides different syntaxes that make it easier to write smart contracts on Tezos.
In this tutorial, you will learn how to:
- Create a wallet
- Get tokens from a faucet
- Code a contract in SmartPy, including:
- Creating a contract in the online IDE
- Defining the storage for the contract
- Defining entrypoints in the contract
- Writing code to run when the entrypoints are called
- Deploy (or originate) the contract to Tezos and set its starting storage value
- Look up the current state of the contract
- Call the contract
What is a smart contract?
A smart contract is a computer program that is stored on a blockchain and runs on a blockchain. Because the blockchain is spread across many computer nodes, you don't have to think about where to host the program or worry whether a computer will run it or not. Responsibility for running the contract is distributed across all of the nodes in the Tezos system, so when you deploy a smart contract, you can be confident that it will be available and unmodified when someone wants to run it.
A smart contract has these parts:
- It has persistent storage, data that the contract can read and write
- It has one or more entrypoints, which are a kind of function that clients can call, like endpoints in an API or functions or methods in many programming languages
- It has a Tezos account and can store tez (technically, the contract is itself a type of Tezos account, but you can think of it as a program with a Tezos account)
Tutorial contract
The contract that you deploy in this tutorial stores a string value. It provides entrypoints that clients can call to change the value of that string:
- The
replace
endpoint accepts a new string as a parameter and stores that string, replacing the existing string. - The
append
endpoint accepts a new string as a parameter and appends it to the existing string.
After you deploy the contract, you or any other user can call it from various sources, including web applications, other contracts, and the Octez command-line client.