Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 6f99c57

Browse files
Info about encoding storage values to Micheline for deployment (#320)
* Don't say "simply" * Don't use "once" to mean "when" * This isn't a prereq because we cover the online IDEs on this page * Compiling storage values in LIGO and SmartPy
1 parent baca88d commit 6f99c57

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

docs/smart-contracts/deploying.md

+85-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
title: Deploying smart contracts
33
authors: 'Yuxin Li'
44
last_update:
5-
date: 6 November 2023
5+
date: 13 February 2024
66
---
77
## Introduction
88
In Tezos, deploying a smart contract is often referred to as “origination”. This process essentially creates a new account that holds the smart contract's script. Contracts originated in this manner have addresses that start with `KT1`, which distinguishes them from the user accounts with addresses beginning with `tz1`, `tz2`, or `tz3`.
99

1010
## Prerequisites
1111
- Compile your contract and its initial storage
1212
- Set up an wallet account on Tezos with some tez to pay the fees
13-
- Ensure that you have obtained the [Tezos client](../developing/octez-client/installing)
1413

1514
## Deploying a smart contract
1615
Generally, there are two methods for deploying your smart contracts: either using the command line in your terminal or deploying through an online IDE.
@@ -31,12 +30,93 @@ where:
3130
- `GAZ_FEE` is a specified maximal fee the user is willing to pay for this operation (using the --burn-cap parameter).
3231

3332
### Deploying via online IDE
34-
As for deploying through your online IDE, if you are using LIGO or SmartPy programming languages, you can simply deploy your smart contracts through their respective online IDEs.
33+
As for deploying through your online IDE, if you are using LIGO or SmartPy programming languages, you can deploy your smart contracts through their respective online IDEs.
3534
- [SmartPy online IDE](https://smartpy.io/)
3635
- [LIGO online IDE](https://ligolang.org/?lang=jsligo)
3736

37+
## Compiling the initial storage value
38+
39+
When you deploy a contract, you initialize its storage.
40+
The initial value of the storage must be a Micheline value, which is the format for variables in Michelson smart contracts.
41+
The high-level languages provide tools to compile the initial values of smart contracts into Micheline values.
42+
43+
### Compiling LIGO storage values
44+
45+
For LIGO smart contracts, you can use the `ligo compile storage` command.
46+
For example, assume that a JsLIGO contract has a storage value that includes a list of integers, a string, and an integer:
47+
48+
```ligolang
49+
type storage = [
50+
list<int>,
51+
string,
52+
int,
53+
];
54+
```
55+
56+
When this contract is compiled to Michelson, the storage line of the contract looks like this:
57+
58+
```michelson
59+
storage (pair (list int) string int) ;
60+
```
61+
62+
To compile an initial value to this format, you can pass a JsLIGO value to the `ligo compile storage` command, as in this example:
63+
64+
```bash
65+
ligo compile storage MyContract.jsligo '[list([1,2,3,4]), "start", 0]'
66+
```
67+
68+
The result is the Micheline value, as in this example:
69+
70+
```michelson
71+
(Pair { 1 ; 2 ; 3 ; 4 } "start" 0)
72+
```
73+
74+
Then you can use this Micheline value as the initial storage value for the contract:
75+
76+
```bash
77+
octez-client originate contract MyContract \
78+
transferring 0 from my_account \
79+
running MyContract.tz --init '(Pair { 1 ; 2 ; 3 ; 4 } "start" 0)' \
80+
--burn-cap 1
81+
```
82+
83+
### Compiling SmartPy storage values
84+
85+
SmartPy lets you set the initial value of the contract storage in the smart contract code in the `__init__` function.
86+
For example, this contract defines three storage variables and sets their initial values:
87+
88+
```python
89+
import smartpy as sp
90+
91+
@sp.module
92+
def main():
93+
class MyList(sp.Contract):
94+
def __init__(self):
95+
self.data.ListOfIntegers = [1,2,3,4]
96+
self.data.MyString = "hello"
97+
self.data.MyInteger = 5
98+
```
99+
100+
Now you can compile and deploy the contract via the online IDE with these starting values.
101+
102+
If you want to deploy the contract with the Octez client, add a test to the contract and run the test with the command `python MyContract.py`.
103+
One of the files this command creates ends in `storage.tz` and contains the Micheline value of the initial storage, as in this example:
104+
105+
```
106+
(Pair {1; 2; 3; 4} (Pair 5 "hello"))
107+
```
108+
109+
Then you can use this Micheline value as the initial storage value for the contract:
110+
111+
```bash
112+
octez-client originate contract MyContract \
113+
transferring 0 from my_account \
114+
running MyContract.tz --init '(Pair { 1 ; 2 ; 3 ; 4 } "start" 0)' \
115+
--burn-cap 1
116+
```
117+
38118
## Interacting with the contract
39-
Once you have successfully originated the smart contract and it is included in a baked block, there are two ways to interact with it: through command lines or through a block explorer.
119+
When you have successfully originated the smart contract and it is included in a baked block, there are two ways to interact with it: through command lines or through a block explorer.
40120

41121
### Interacting through command lines
42122
The first method involves interacting with the contract's entry points using command lines.
@@ -83,7 +163,7 @@ A blockchain explorer is an efficient and user-friendly tool that enables you to
83163
- [Better Call Dev](https://better-call.dev/)
84164
- [TzKT](https://tzkt.io/)
85165

86-
To interact with a contract, simply copy its address into one of these blockchain explorers. Below is the user interface for interacting with a contract through Better Call Dev:
166+
To interact with a contract, copy its address into one of these blockchain explorers. Below is the user interface for interacting with a contract through Better Call Dev:
87167

88168
![UI for Better Call Dev](/img/tutorials/better-call.png)
89169

0 commit comments

Comments
 (0)