button.
2. In the Keypair Manager window, import the account that you created earlier or create and fund a new account to use with the IDE.
* To import the account that you created earlier, export the private key from your wallet app, click **Import** in the Keypair Manager window, and paste the private key.
Now you can use your account in the IDE.
* To create an account to use with the IDE, click **Create** in the Keypair Manager window, give the new keypair a name, and click **Create**.
Then, copy the address of the keypair and get tez from the faucet as you did in [Creating and funding a wallet](#creating-and-funding-a-wallet).
4. In the IDE, create a project from the empty template and select the JsLIGO syntax, as shown in this picture:
The IDE creates a project and a contract file named `Contract.jsligo`.
5. In the contract file, create a namespace named `Counter` to hold the code for the contract:
```jsligo
namespace Counter {
}
```
6. Inside the namespace, create a TypeScript type to set the storage type to an integer:
```jsligo
type storage = int;
```
7. Add this code to define the return type for the entrypoints.
Tezos entrypoints return two values: a list of other operations to call and the new value of the contract's storage.
```jsligo
type returnValue = [list
3. Click **Run**.
At the bottom of the window, the Result field shows the response `(LIST_EMPTY(), 42)`.
This response means that the contract did not call any other contracts, so the list of operations is empty.
Then it shows the new value of the storage.
You can test the decrement function in the same way.
If you see any errors, make sure that the code of your contract matches the code in the previous section.
4. Test the `Reset` entrypoint in the same way, but pass `unit` as the input parameter and any integer in the storage field.
The `Reset` entrypoint takes no parameters, but technically it accepts the value `unit`, which means no parameter.
The Result field shows the response `(LIST_EMPTY(), 0)`, which means that the storage value is now 0.
3. On the left side of the page, under **Actions**, click **Compile**, and in the Compile window, click **Compile** again.
If the compilation succeeds, the IDE prints the compiled code to the terminal and saves it to the file `build/contracts/Contract.tz`.
You can see the code by expanding your project on the left side of the page, under `.workspaces`, and double-clicking `Contract.tz`.
If you see error messages, verify that your contract code matches the code in the previous section.
Now you can deploy the contract.
## Deploying (originating) to the testnet
Deploying a contract to the network is called "originating."
Originating the contract requires a small amount of Tezos tokens as a fee.
1. On the left side of the page, under **Actions**, click **Deploy**.
You may see a warning that the initial storage is not set.
You can ignore this warning because you can set the initial storage now.
2. In the Deploy contract window, in the **Init storage** field, set the initial value for the contract's storage to an integer.
3. In the **Signer** field, make sure your account is selected.
4. Click **Estimate**.
The window shows the estimated fees to deploy the contract, as in this picture:
5. Click **Deploy**.
The deployment process can take a few minutes.
When the contract is deployed, the Deploy contract window shows the address at the bottom of the window.
6. Copy the address of the deployed contract, which starts with `KT1`.
:::warning
Copy the contract address now, because it will not be shown again.
:::
Now you can call the contract from any Tezos client, including web applications and command-line applications like [The Octez client](/developing/octez-client).
## Calling the contract
These steps show you how to inspect the contract with a block explorer, which is a web application that shows information about Tezos.
It also allows you to call the contract.
1. Open the block explorer Better Call Dev at this link: https://better-call.dev/
2. Paste the address of the contract in the search field and press Enter.
The block explorer shows information about the contract, including recent transactions and the current state of its storage.
3. Try calling one of the entrypoints:
1. Go to the **Storage** tab and check the current state of the storage, which should be the integer that you put in the Deploy window.
2. Go to the **Interact** tab.
This tab shows the entrypoints in the contract and lets you use them.
3. For the `increment` entrypoint, in the **Parameters** section, put an integer in the field, as shown in this image:
4. Click **Execute** and then click **Wallet**.
5. Select your wallet and connect it to the application.
6. Confirm the transaction in your wallet.
7. Wait for a success message that says "The transaction has successfully been broadcasted to the network."
8. Go back to the **Storage** tab and see the new value of the storage, as in this picture:
## Summary
Now the contract is running on the Tezos blockchain.
You or any other user can call it from any source that can send transactions to Tezos, including Octez, dApps, and other contracts.
If you want to continue working with this contract, here are some ideas:
* Change permissions for the contract so only your account can call its entrypoints
* Add your own entrypoints and originate a new contract; note that you cannot update the existing contract after it is deployed
* Create a dApp to call the contract from a web application, similar to the dApp that you create in the tutorial [Build a simple web application](/tutorials/build-your-first-app/)
# Deploy a smart contract with CameLIGO
Estimated time: 30 minutes
This tutorial covers writing and deploying a simple smart contract with the LIGO programming language.
Specifically, this tutorial uses the CameLIGO version of LIGO, which has syntax similar to OCaml, but you don't need any experience with OCaml or LIGO to do this tutorial.
* If you are more familiar with JavaScript, try [Deploy a smart contract with JsLIGO](/tutorials/smart-contract/jsligo).
* If you are more familiar with Python, try [Deploy a smart contract with SmartPy](/tutorials/smart-contract/smartpy).
* To learn the Archetype language, try [Deploy a smart contract with Archetype](/tutorials/smart-contract/archetype).
LIGO 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) to make it easier to write smart contracts on Tezos.
In this tutorial, you will learn how to:
* Create a wallet to store cryptocurrency tokens
* Get free tez tokens (the native cryptocurrency token on Tezos) from a faucet
* Code a contract in LIGO, including:
* 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:
* Persistent storage, data that the contract can read and write
* 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
* A Tezos account that can store tokens (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 single integer.
It provides entrypoints that clients can call to change the value of that integer:
* The `increment` entrypoint accepts an integer as a parameter and adds that integer to the value in storage
* The `decrement` entrypoint accepts an integer as a parameter and subtracts that integer from the value in storage
* The `reset` entrypoint takes no parameters and resets the value in storage to 0
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.
However, no one can prevent it from running or tamper with its code or its storage.
## Creating and funding a wallet
To deploy and work with the contract, you need a wallet and some tez tokens.
You can get test tokens for free on the Ghostnet test network:
1. Install a Tezos-compatible wallet.
Which wallet you install is up to you and whether you want to install a wallet on your computer, in a browser extension, or as a mobile app.
If you don't know which one to choose, try the [Temple](https://templewallet.com/) browser extension.
Desktop wallets for Tezos include the [Temple](https://templewallet.com/) browser extension, [Kukai](https://wallet.kukai.app/), and [Umami](https://umamiwallet.com/).
Mobile apps include [Temple](https://templewallet.com/), [Kukai](https://wallet.kukai.app/), and [Umami](https://umamiwallet.com/).
2. Switch the wallet to use the Ghostnet testnet instead of Tezos Mainnet.
Ghostnet is a network for testing Tezos applications where tokens are free so you don't have to spend real currency to work with your applications.
For example, for the Temple browser wallet, click **Tezos Mainnet** at the top and then click **Ghostnet Testnet**, as in this picture:

3. From your wallet, get the address of your account, which starts with `tz1`.
This is the address that applications use to work with your wallet.
4. Go to the Ghostnet faucet page at https://faucet.ghostnet.teztnets.com.
5. On the faucet page, paste your wallet address into the input field labeled "Or fund any address" and click the button for the amount of tez to add to your wallet.
20 tez is enough to work with the tutorial contract, and you can return to the faucet later if you need more tez.
It may take a few minutes for the faucet to send the tokens and for those tokens to appear in your wallet.
You can use the faucet as much as you need to get tokens on the testnet, but those tokens are worthless and cannot be used on Mainnet.

Now you have an account and funds that you can use to work with Tezos.
## Creating the contract
The contract that you will create has these basic parts:
* A type that describes the contract's storage, in this case an integer.
The storage can be a primitive type such as an integer, string, or timestamp, or a complex data type that contains multiple values.
For more information on contract data types, see [Data types](/smart-contracts/data-types).
* Functions called entrypoints that run code when clients call the contract.
* A type that describes the return value of the entrypoints.
Follow these steps to create the code for the contract:
1. Open the LIGO online IDE at https://ide.ligolang.org/.
You can work with LIGO code in any IDE, but this online IDE keeps you from having to install software on your computer, and it also simplifies the process of deploying contracts.
2. At the top right of the page, in the **Network** menu, select Ghostnet, as shown in this picture:

3. Connect a wallet to the IDE:
1. At the top right of the page, click the **Keypair Manager**
button.
2. In the Keypair Manager window, import the account that you created earlier or create and fund a new account to use with the IDE.
* To import the account that you created earlier, export the private key from your wallet app, click **Import** in the Keypair Manager window, and paste the private key.
Now you can use your account in the IDE.
* To create an account to use with the IDE, click **Create** in the Keypair Manager window, give the new keypair a name, and click **Create**.
Then, copy the address of the keypair and get tez from the faucet as you did in [Creating and funding a wallet](#creating-and-funding-a-wallet).
4. In the IDE, create a project from the empty template and select the CameLIGO syntax, as shown in this picture:
The IDE creates a project and a contract file named `Contract.mligo`.
5. In the contract file, create a type to set the storage type to an integer:
```cameligo
type storage = int
```
6. Add this code to define the return type for the entrypoints.
Tezos entrypoints return two values: a list of other operations to call and the new value of the contract's storage.
```cameligo
type returnValue = operation list * storage
```
7. Add the code for the increment and decrement entrypoints:
```cameligo
// Increment entrypoint
[@entry] let increment (delta : int) (store : storage) : returnValue =
[], store + delta
// Decrement entrypoint
[@entry] let decrement (delta : int) (store : storage) : returnValue =
[], store - delta
```
These functions begin with the `@entry` annotation to indicate that they are entrypoints.
They accept two parameters: the change in the storage value (an integer) and the current value of the storage (in the `storage` type that you created earlier in the code).
They return a value of the type `returnValue` that you created in the previous step.
Each function returns an empty list of other operations to call and the new value of the storage.
8. Add this code for the reset entrypoint:
```cameligo
// Reset entrypoint
[@entry] let reset (() : unit) (_ : storage) : returnValue =
[], 0
```
This function is similar to the others, but it does not take the current value of the storage into account.
It always returns an empty list of operations and 0.
The complete contract code looks like this:
```cameligo
type storage = int
type returnValue = operation list * storage
// Increment entrypoint
[@entry] let increment (delta : int) (store : storage) : returnValue =
[], store + delta
// Decrement entrypoint
[@entry] let decrement (delta : int) (store : storage) : returnValue =
[], store - delta
// Reset entrypoint
[@entry] let reset (() : unit) (_ : storage) : returnValue =
[], 0
```
## Testing and compiling the contract
Before you can deploy the contract to Tezos, you must compile it to Michelson, the base language of Tezos contracts.
1. Set the compiler to target the module to compile in your code:
1. On the left side of the page, under **Actions**, click **Project Settings**.
2. On the Project Settings tab, in the **Module name** field, set the module name to `Counter`.
3. Close the Project Settings tab.
2. Test the contract by passing parameters and the storage value to the LIGO `dry-run` command:
1. On the left side of the page, under **Actions**, click **Dry Run**.
2. In the Dry Run window, select the `Increment` entrypoint, set the input parameter to `32` and the storage to `10`.
The Dry Run window looks like this:
3. Click **Run**.
At the bottom of the window, the Result field shows the response `(LIST_EMPTY(), 42)`.
This response means that the contract did not call any other contracts, so the list of operations is empty.
Then it shows the new value of the storage.
You can test the decrement function in the same way.
If you see any errors, make sure that the code of your contract matches the code in the previous section.
4. Test the `Reset` entrypoint in the same way, but pass `unit` as the input parameter and any integer in the storage field.
The `Reset` entrypoint takes no parameters, but technically it accepts the value `unit`, which means no parameter.
The Result field shows the response `(LIST_EMPTY(), 0)`, which means that the storage value is now 0.
3. On the left side of the page, under **Actions**, click **Compile**, and in the Compile window, click **Compile** again.
If the compilation succeeds, the IDE prints the compiled code to the terminal and saves it to the file `build/contracts/Contract.tz`.
You can see the code by expanding your project on the left side of the page, under `.workspaces`, and double-clicking `Contract.tz`.
If you see error messages, verify that your contract code matches the code in the previous section.
Now you can deploy the contract.
## Deploying (originating) to the testnet
Deploying a contract to the network is called "originating."
Originating the contract requires a small amount of Tezos tokens as a fee.
1. On the left side of the page, under **Actions**, click **Deploy**.
You may see a warning that the initial storage is not set.
You can ignore this warning because you can set the initial storage now.
2. In the Deploy contract window, in the **Init storage** field, set the initial value for the contract's storage to an integer.
3. In the **Signer** field, make sure your account is selected.
4. Click **Estimate**.
The window shows the estimated fees to deploy the contract, as in this picture:
5. Click **Deploy**.
The deployment process can take a few minutes.
When the contract is deployed, the Deploy contract window shows the address at the bottom of the window.
6. Copy the address of the deployed contract, which starts with `KT1`.
:::warning
Copy the contract address now, because it will not be shown again.
:::
Now you can call the contract from any Tezos client, including web applications and command-line applications like [The Octez client](/developing/octez-client).
## Calling the contract
These steps show you how to inspect the contract with a block explorer, which is a web application that shows information about Tezos.
It also allows you to call the contract.
1. Open the block explorer Better Call Dev at this link: https://better-call.dev/
2. Paste the address of the contract in the search field and press Enter.
The block explorer shows information about the contract, including recent transactions and the current state of its storage.
3. Try calling one of the entrypoints:
1. Go to the **Storage** tab and check the current state of the storage, which should be the integer that you put in the Deploy window.
2. Go to the **Interact** tab.
This tab shows the entrypoints in the contract and lets you use them.
3. For the `increment` entrypoint, in the **Parameters** section, put an integer in the field, as shown in this image:
4. Click **Execute** and then click **Wallet**.
5. Select your wallet and connect it to the application.
6. Confirm the transaction in your wallet.
7. Wait for a success message that says "The transaction has successfully been broadcasted to the network."
8. Go back to the **Storage** tab and see the new value of the storage, as in this picture:
## Summary
Now the contract is running on the Tezos blockchain.
You or any other user can call it from any source that can send transactions to Tezos, including Octez, dApps, and other contracts.
If you want to continue working with this contract, here are some ideas:
* Change permissions for the contract so only your account can call its entrypoints
* Add your own entrypoints and originate a new contract; note that you cannot update the existing contract after it is deployed
* Create a dApp to call the contract from a web application, similar to the dApp that you create in the tutorial [Build a simple web application](/tutorials/build-your-first-app/)
# Deploy a smart contract with SmartPy
Estimated time: 30 minutes
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](/tutorials/smart-contract/cameligo).
* If you are more familiar with JavaScript, try [Deploy a smart contract with JsLIGO](/tutorials/smart-contract/jsligo).
* To learn the Archetype language, try [Deploy a smart contract with Archetype](/tutorials/smart-contract/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) to make it easier to write smart contracts on Tezos.
In this tutorial, you will learn how to:
* Create a wallet to manage an account containing cryptocurrency tokens
* Get free tez tokens (the native cryptocurrency token on Tezos) 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
* 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:
* Persistent storage, data that the contract can read and write
* 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
* A Tezos account that can store tokens (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` entrypoint accepts a new string as a parameter and stores that string, replacing the existing string.
* The `append` entrypoint 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.
However, no one can prevent it from running or tamper with its code or its storage.
## Creating and funding a wallet
To deploy and work with the contract, you need a wallet and some tez tokens.
1. Install a Tezos-compatible wallet.
Which wallet you install is up to you and whether you want to install a wallet on your computer, in a browser extension, or as a mobile app.
For options, see [Installing and funding a wallet](/developing/wallet-setup)
2. Switch the wallet to use the Shadownet testnet instead of Tezos Mainnet.
Shadownet is a network for testing Tezos applications where tokens are free so you don't have to spend real currency to work with your applications.
For example, for the Temple browser wallet:
1. Expand the menu at top right and then turn on **Testnet mode**, as in this picture:
2. Above the list of tokens, click the display options button:
3. Under **Filter by network**, expand **All Networks**.
4. Select **Shadownet**:
Now Temple shows your token balances on the Shadownet test network.
3. From your wallet, get the address of your account, which starts with `tz1`.
This is the address that applications use to work with your wallet.
4. Go to the Shadownet faucet page at https://faucet.shadownet.teztnets.com.
5. On the faucet page, connect your wallet, or paste your wallet address into the input field labeled "Fund any address" and click the button for the amount of tez to add to your wallet.
20 tez is enough to work with the tutorial contract, and you can return to the faucet later if you need more tez.
Depending on the amount you requested, it may take a few seconds or minutes for the faucet to send the tokens and for those tokens to appear in your wallet.
You can use the faucet as much as you need to get tokens on the testnet, but those tokens are worthless and cannot be used on Mainnet.

Now you have an account and funds that you can use to work with Tezos.
## Creating the contract
The contract that you will create has these basic parts:
* A function that initializes the contract and sets the starting value for its storage.
* Functions called entrypoints that run code when clients call the contract.
* Automated tests that verify that the contract works as expected.
Follow these steps to create the code for the contract:
1. Open the SmartPy online IDE at https://smartpy.io/ide.
You can work with SmartPy code in any IDE, but this online IDE keeps you from having to install software on your computer, and it also simplifies the process of deploying contracts.
2. In the code editor, add this line of code to import SmartPy:
```python
import smartpy as sp
```
3. Add this code that creates the entrypoints:
```python
@sp.module
def main():
class StoreGreeting(sp.Contract):
def __init__(self, greeting): # Note the indentation
# Initialize the storage with a string passed at deployment time
# Cast the greeting parameter to a string
sp.cast(greeting, sp.string)
self.data.greeting = greeting
@sp.entrypoint # Note the indentation
def replace(self, params):
self.data.greeting = params.text
@sp.entrypoint # Note the indentation
def append(self, params):
self.data.greeting += params.text
```
Indentation is significant in Python, so make sure that your indentation matches this code.
The first two lines create a SmartPy module, which indicates that the code is SmartPy instead of ordinary Python.
Then the code creates a class named StoreGreeting, which represents the smart contract.
The contract has an `__init__` function, which runs when the contract is deployed.
In this case, the function sets the initial value of the storage to a parameter that you pass when you deploy the contract.
This storage value is a string, but the storage can be another primitive type such as an integer or timestamp, or a complex data type that contains multiple values.
For more information on contract data types, see [Data types](/smart-contracts/data-types).
4. Add this code, which creates automated tests:
```python
# Automated tests that run on simulation
@sp.add_test()
def test():
# Initialize the test scenario
scenario = sp.test_scenario("StoreGreeting", main)
scenario.h1("StoreGreeting")
# Initialize the contract and pass the starting value
contract = main.StoreGreeting("Hello")
scenario += contract
# Verify that the value in storage was set correctly
scenario.verify(contract.data.greeting == "Hello")
# Test the entrypoints and check the new storage value
contract.replace(text = "Hi")
contract.append(text = ", there!")
scenario.verify(contract.data.greeting == "Hi, there!")
```
When you run the SmartPy file, SmartPy runs a simulation in which it tests and compiles the contract.
In this case, the tests verify that the replace and append endpoints work.
For more information about SmartPy and tests, see the [SmartPy documentation](https://smartpy.tezos.com/).
The SmartPy online IDE looks like this:

The complete contract looks like this:
```python
import smartpy as sp
@sp.module
def main():
class StoreGreeting(sp.Contract):
def __init__(self, greeting): # Note the indentation
# Initialize the storage with a string passed at deployment time
# Cast the greeting parameter to a string
sp.cast(greeting, sp.string)
self.data.greeting = greeting
@sp.entrypoint # Note the indentation
def replace(self, params):
self.data.greeting = params.text
@sp.entrypoint # Note the indentation
def append(self, params):
self.data.greeting += params.text
# Automated tests that run on simulation
@sp.add_test()
def test():
# Initialize the test scenario
scenario = sp.test_scenario("Test scenario", main)
scenario.h1("StoreGreeting")
# Initialize the contract and pass the starting value
contract = main.StoreGreeting("Hello")
scenario += contract
# Verify that the value in storage was set correctly
scenario.verify(contract.data.greeting == "Hello")
# Test the entrypoints and check the new storage value
contract.replace(text = "Hi")
contract.append(text = ", there!")
scenario.verify(contract.data.greeting == "Hi, there!")
```
## Testing and compiling the contract
Before you can deploy the contract to Tezos, you must run it in the IDE, which automatically compiles it to Michelson, the base language of Tezos contracts.
Then, the IDE also automatically runs the tests.
1. Compile the contract and run the tests by clicking the **Run Code** button:

The right-hand pane of the online IDE shows the results of the simulation, compilation, and testing process.
The first step is simulating the deployment (origination) of the contract.
The simulation assigns the contract a temporary address and shows the initial state of its storage:
Then, the simulation runs the test cases and shows the results of each call to an entrypoint:
## Deploying (originating) to the testnet
Deploying a contract to the network is called "originating."
Originating the contract requires a small amount of Tezos tokens as a fee.
1. Under the origination step, click **Deploy contract**.
The IDE shows the compiled Michelson code of the contract, which is the language that smart contracts use on Tezos.
2. Below the Michelson code, click **Continue**.
3. In the new window, under "Node and Network," select the Shadownet testnet and accept the default RPC node, as in this picture:
4. Under "Wallet," click **Select Account**.
5. In the pop-up window, connect your wallet.
For most wallets, use the octez.connect (or Beacon) tab.
6. When your wallet is connected, click **Validate**.
The Origination page shows your wallet information:
7. Under "Contract Origination Parameters," click **Estimate cost**.
The Fee field shows the estimated cost to deploy the contract in tez.
8. At the bottom of the page, click **Deploy Contract**.
9. In the pop-up window, click **Accept**.
10. Approve the transaction in your wallet app.
The "Result" section shows information about the deployed contract, including its address:
11. Copy the contract address, which starts with `KT1`.
:::note
Be sure to save the contract address because it is not shown in the SmartPy online IDE again.
If you close the window and forget the address, you can look up your account address in a block explorer; the block explorer shows your recent transactions, including smart contracts that you deployed.
:::
12. Open the contract in the block explorer Better Call Dev:
1. Click **Open explorer**.
The IDE shows information about the contract and links to popular block explorers.
2. Click **Explore with Better Call Dev**.
You can also go directly to https://better-call.dev/ in a new browser tab and search for the contract by its address.
The block explorer shows information about the contract, including recent transactions and the current state of its storage:
13. Try calling one of the entrypoints:
1. Go to the **Storage** tab and check the current state of the storage.
If you just originated the contract, the storage is "Hello" because that's the value set in the smart contract code.
2. Go to the **Interact** tab.
This tab shows the entrypoints in the contract and lets you use them.
3. For the `append` entrypoint, in the **Parameters** section, put some text in the field, as shown in this image:
4. Click **Execute** and then click **Wallet**.
5. Select your wallet and connect it to the application.
6. Confirm the transaction in your wallet.
7. Wait for a success message that says "The transaction has successfully been broadcasted to the network."
8. Go back to the **Storage** tab and see that the text that you put in the parameter has been added to the contract storage, as in this picture:
## Summary
Now the contract is running on the Tezos blockchain.
You or any other user can call it from any source that can send transactions to Tezos, including Octez, dApps, and other contracts.
If you want to continue working with this contract, here are some ideas:
* Change permissions for the contract so only your account can call its entrypoints
* Add your own entrypoints and originate a new contract; note that you cannot update the existing contract after it is deployed
* Create a dApp to call the contract from a web application, similar to the dApp that you create in the tutorial [Build a simple web application](/tutorials/build-your-first-app/)
# Deploy a smart contract with Archetype
Estimated time: 30 minutes
This tutorial covers writing a smart contract and deploying it to Tezos in the Archetype programming language.
It uses the completium-cli command-line tool, which lets you work with Archetype contracts and Tezos from the command line.
* If you are more familiar with Python, try [Deploy a smart contract with SmartPy](/tutorials/smart-contract/smartpy).
* If you are more familiar with OCaml, try [Deploy a smart contract with CameLIGO](/tutorials/smart-contract/cameligo).
* If you are more familiar with JavaScript, try [Deploy a smart contract with JsLIGO](/tutorials/smart-contract/jsligo).
In this tutorial, you will learn how to:
* Create a wallet to store cryptocurrency tokens
* Get free tez tokens (the native cryptocurrency token on Tezos) from a faucet
* Code a contract in Archetype, including:
* Defining the storage for the contract and its initial value
* Defining entrypoints in the contract
* Writing code to run when the entrypoints are called
* Deploy (or originate) the contract to Tezos
* Look up the current state of the contract
* Call the contract from the command line
## 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:
* Persistent storage, data that the contract can read and write
* 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
* A Tezos account that can store tokens (technically, the contract is itself a type of Tezos account, but you can think of it as a program with a Tezos account)
## The Archetype language
Archetype is a high-level language designed specifically for writing Tezos smart contracts.
It has features that help you write smart contracts, including:
* Clear syntax that maps closely with how smart contracts work
* Enhancements that simplify working with storage
* Tools that help you verify conditions before running code, such as ensuring that the caller is authorized to run the entrypoint
* The ability to set up a contract as a state machine, which gives the contract a state and manages transitions between states
* The ability to verify that the contract does what it says it does through the process of formal verification
Like the other languages that Tezos accepts, Archetype code is compiled to Michelson to run on the blockchain.
For more information about Archetype, see https://archetype-lang.org/.
## Tutorial contract
The contract that you deploy in this tutorial stores a single integer.
It provides entrypoints that clients can call to change the value of that integer:
* The `increment` entrypoint accepts an integer as a parameter and adds that integer to the value in storage
* The `decrement` entrypoint accepts an integer as a parameter and subtracts that integer from the value in storage
* The `reset` entrypoint takes no parameters and resets the value in storage to 0
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.
However, no one can prevent it from running or tamper with its code or its storage.
## Prerequisites
To run this tutorial, you need the completium-cli program:
1. Make sure that NPM is installed by running this command in your command-line terminal:
```bash
npm --version
```
If NPM is not installed, install Node.JS on your computer, which includes NPM, from this link: https://nodejs.org/en.
2. Install completium-cli by running this command:
```bash
npm install -g @completium/completium-cli
```
You can verify that completium-cli installed by running this command:
```bash
completium-cli version
```
If you see a message with the version of completium-cli, it is installed correctly.
3. Initialize completium-cli by running this command:
```bash
completium-cli init
```
## Using a testnet
Before you deploy your contract to the main Tezos network (referred to as *Mainnet*), you can deploy it to a testnet.
Testnets are useful for testing Tezos operations because testnets provide tokens for free so you can work with them without spending real tokens.
Tezos testnets are listed on this site: https://teztnets.com/.
The [Shadownet](https://teztnets.com/shadownet-about) testnet is a good choice for testing because it is intended to be long-lived, as opposed to shorter-term testnets that allow people to test new Tezos features.
By default, completium-cli uses Shadownet, but these steps verify the network:
1. Verify that completium-cli is set to use Shadownet by running this command:
```bash
completium-cli show endpoint
```
The response shows the RPC endpoint that completium-cli is using, which is its access point to the Tezos network.
If the response shows `Current network: shadow`, it is using Shadownet.
2. If completium-cli is not using Shadownet, switch to Shadownet by running this command, selecting any endpoint labeled "shadownet," and pressing Enter:
```bash
completium-cli switch endpoint
```
## Creating a local wallet
Deploying and using a smart contract costs fees, so you need a local wallet and XTZ tokens.
You could use the default accounts that are included in completium-cli, but follow these steps to create your own local wallet on a test network:
1. Run the following command to generate a local wallet, replacing `local_wallet` with a name for your wallet:
```bash
completium-cli generate account as local_wallet
```
2. Switch to the account that you created by running this command, selecting the new account, and pressing Enter:
```bash
completium-cli switch account
```
3. Get the address for the wallet by running this command:
```bash
completium-cli show account
```
The result shows the address of the account, which begins with "tz1".
You need the wallet address to send funds to the wallet, to deploy the contract, and to send transactions to the contract.
4. Copy the address for the account, which is labeled as the "public key hash" in the response to the previous command.
The address starts with "tz1".
5. On the testnets page at https://teztnets.com/, click the faucet link for the Shadownet testnet, which is at https://faucet.shadownet.teztnets.com.
6. On the faucet page, paste your wallet address into the input field labeled "Or fund any address" and click the button for the amount of XTZ to add to your wallet.
1 XTZ is enough for the tutorial.
It may take a few minutes for the faucet to send the tokens and for those tokens to appear in your wallet.
You can use the faucet as much as you need to get tokens on the testnet, but those tokens are worthless and cannot be used on Mainnet.

7. Run this command to check the balance of your wallet:
```bash
completium-cli show account
```
If your wallet is set up correctly and the faucet has sent tokens to it, the response includes the balance of your wallet.
## Create the contract
The contract that you will create has these basic parts:
* A variable that represents the contract's storage, in this case an integer.
Contracts can have storage in the form of primitive types such as an integer, string, or timestamp, or a complex data type that contains multiple values.
For more information on contract data types, see [Data types](/smart-contracts/data-types).
* Internal functions called entrypoints that run code when clients call the contract.
Follow these steps to create the code for the contract:
1. Run this command to create the contract file:
```bash
touch counter.arl
```
2. Open the `counter.arl` file in any text editor.
3. At the top of the file, name the contract by putting the name after the `archetype` keyword:
```archetype
archetype Counter
```
4. Define the storage for the contract by adding this line:
```archetype
variable value : int = 10
```
This line creates a variable in the contract's storage with the name "value."
It is an integer type and has the initial value of 10.
Any variables that you create with the `variable` keyword at the top level of the contract become part of its persistent storage.
5. Add the code for the increment and decrement entrypoints:
```archetype
// Increment entrypoint
entry increment(delta : int) {
value += delta
}
// Decrement entrypoint
entry decrement(delta : int) {
value -= delta
}
```
These functions begin with the `entry` keyword to indicate that they are entrypoints.
They accept one parameter: the change in the storage value, which is an integer named `delta`.
One function adds the parameter to the value of the `value` variable and the other subtracts it.
6. Add this code for the reset entrypoint:
```archetype
// Reset entrypoint
entry reset() {
value := 0
}
```
This function is similar to the others, but it does not take a parameter.
It always sets the `value` variable to 0.
The complete contract code looks like this:
```archetype
archetype Counter
variable value : int = 0
// Increment entrypoint
entry increment(delta : int) {
value += delta
}
// Decrement entrypoint
entry decrement(delta : int) {
value -= delta
}
// Reset entrypoint
entry reset() {
value := 0
}
```
## Deploying (originating) to the testnet
Deploying a contract to the network is called "originating."
Originating the contract requires a small amount of Tezos tokens as a fee.
1. Run the following command to originate the smart contract:
```bash
completium-cli deploy Counter.arl
```
The command line shows information about the transaction, including the name of the originating account, the target network, and the cost to deploy it.
By default, it uses the local alias "Counter" to refer to the contract.
2. Press Y to confirm and deploy the contract.
If you see an error that includes the message `contract.counter_in_the_past`, you waited too long before pressing Y.
Run the `deploy` command again and promptly press Y to confirm it.
3. Print information about the contract by running this command:
```bash
completium-cli show contract Counter
```
The response shows information about the contract, including its address on Shadownet, which starts with "KT1".
You can use this information to look up the contract on a block explorer.
4. Verify that the contract deployed successfully by finding it on a block explorer:
1. Open a Tezos block explorer such as [TzKT](https://tzkt.io) or [Better Call Dev](https://better-call.dev/).
2. Set the explorer to Shadownet instead of Mainnet.
3. Paste the contract address, which starts with `KT1`, into the search field and press Enter.
4. Go to the Storage tab to see that the initial value of the storage is 10.
5. Run this command to see the current value of the contract storage:
```bash
completium-cli show storage Counter
```
## Calling the contract
Now you can call the contract from any Tezos client, including completium-cli.
To increment the current storage by a certain value, call the `increment` entrypoint, as in this example:
```bash
completium-cli call Counter --entry increment --arg '{ "int": 5 }'
```
The CLI shows information about the call including the network and transaction fee and prompts you to press `Y` to confirm before it sends the transaction to the network.
The "Operation injected" message indicates that the Completium CLI sent the transaction successfully.
To decrement the storage, call the `decrement` entrypoint, as in this example:
```bash
completium-cli call Counter --entry decrement --arg '{ "int": 2 }'
```
Finally, to reset the current storage to zero, call the `reset` entrypoint, as in this example:
```bash
completium-cli call Counter --entry reset
```
Then, you can verify the updated storage on the block explorer or by running the `completium-cli show storage Counter` command.
## Summary
Now the contract is running on the Tezos blockchain.
You or any other user can call it from any source that can send transactions to Tezos, including command-line clients, dApps, and other contracts.
If you want to continue working with this contract, here are some ideas:
* Change permissions for the contract so only your account can call its entrypoints
* Add your own entrypoints and originate a new contract; note that you cannot update the existing contract after it is deployed
* Create a dApp to call the contract from a web application, similar to the dApp that you create in the tutorial [Build a simple web application](/tutorials/build-your-first-app/)
# Create your minimum dapp on Tezos
Estimated time: 2 hours
> dApp : A decentralized application is a type of distributed open source software application that runs on a peer-to-peer (P2P) blockchain network rather than on a single computer. DApps are visibly similar to other software applications that are supported on a website or mobile device.
This tutorial shows you how to create a poke game on smart contract.
The game consists on poking the owner of a smart contract. The smart contract keeps a track of user interactions and stores a trace.
Poke sequence diagram.
```mermaid
sequenceDiagram
Note left of User: Prepare poke transaction
User->>Smartcontract: poke()
Note right of Smartcontract: store(pokeTrace)
```
You will learn :
* How to create a Tezos project with Taqueria.
* How to create a smart contract in JsLIGO.
* How to deploy the smart contract a real testnet named Ghostnet.
* How to create a frontend dApp using Taquito library and interact with a Tezos browser wallet.
* How to use an indexer like TZKT.
## Prerequisites
This tutorial uses Typescript, so it will be easier if you are familiar with JavaScript.
1. Make sure that you have installed these tools:
* [Node.JS and NPM](https://nodejs.org/en/download/): NPM is required to install the web application's dependencies.
* [Taqueria](https://taqueria.io/), version 0.45.0 or later: Taqueria is a platform that makes it easier to develop and test dApps.
* [Docker](https://docs.docker.com/engine/install/): Docker is required to run Taqueria.
* [jq](https://stedolan.github.io/jq/download/): Some commands use the `jq` program to extract JSON data.
* [`yarn`](https://yarnpkg.com/): The frontend application uses yarn to build and run (see this article for details about [differences between `npm` and `yarn`](https://www.geeksforgeeks.org/difference-between-npm-and-yarn/)).
* Any Tezos-compatible wallet that supports Ghostnet, such as [Temple wallet](https://templewallet.com/).
2. Optionally, you can install [`VS Code`](https://code.visualstudio.com/download) to edit your application code in and the [LIGO VS Code extension](https://marketplace.visualstudio.com/items?itemName=ligolang-publish.ligo-vscode) for LIGO editing features such as code highlighting and completion.
Taqueria also provides a [Taqueria VS Code extension](https://marketplace.visualstudio.com/items?itemName=ecadlabs.taqueria-vscode) that helps visualize your project and run tasks.
## The tutorial application
In this tutorial, you create a simple game where the user is poking though a dApp. The user interacts with the smart contract through a web interface, where they can see the current state of the contract and send poke commands to it. The contract responds by updating its storage with the user's address. Alternately, a user can also poke the contract deployed by other users.
The application looks like this:

The code for the completed application is in this GitHub repository: [solution](https://github.com/marigold-dev/training-dapp-1/tree/main/solution)
When you're ready, move to the next section [Create your minimum dApp on Tezos](/tutorials/dapp/part-1) to begin setting up the application.
# Part 1: Create your minimum dApp on Tezos
To start working with the application, you create a Taqueria project and use it to deploy the Poke contract.
Then you set up a web application to connect with a wallet, and then interact with your smart contract.
Before you begin, make sure that you have installed the tools in the [Prerequisites](/tutorials/dapp#prerequisites) section.
## Creating a Taqueria project
Taqueria manages the project structure and keeps it up to date.
For example, when you deploy a new smart contract, Taqueria automatically updates the web app to send transactions to that new smart contract.
Follow these steps to set up a Taqueria project:
On the command-line terminal, run these commands to set up a Taqueria project and install the LIGO and Taquito plugins:
```bash
taq init training
cd training
taq install @taqueria/plugin-ligo
taq install @taqueria/plugin-taquito
taq create contract pokeGame.jsligo
```
## Write the smart contract
1. Edit the **pokeGame.jsligo** file. Remove the default code and paste this code instead.
```jsligo
export type storage = unit;
type return_ = [list| address | people | action |
|---|---|---|
| {contract.address} | {contract.storage.join(", ")} |
| address | trace "contract - feedback - user" | action |
|---|---|---|
| {contract.address} | {(contract.storage !== null && contract.storage.pokeTraces !== null && Object.entries(contract.storage.pokeTraces).length > 0)?Object.keys(contract.storage.pokeTraces).map((k : string)=>contract.storage.pokeTraces[k].receiver+" "+contract.storage.pokeTraces[k].feedback+" "+k+", "):""} |
| address | trace "contract - feedback - user" | action |
|---|---|---|
| {contract.address} | {contractStorages.get(contract.address!) !== undefined && contractStorages.get(contract.address!)!.pokeTraces ? Array.from( contractStorages .get(contract.address!)! .pokeTraces.entries() ).map( (e) => e[1].receiver + ' ' + e[1].feedback + ' ' + e[0] + ',' ) : ''} | { console.log('e', e.currentTarget.value); setContractToPoke(e.currentTarget.value); }} placeholder="enter contract address here" /> |
| address | trace "contract - feedback - user" | action |
|---|---|---|
| {contract.address} | {contractStorages.get(contract.address!) !== undefined && contractStorages.get(contract.address!)!.pokeTraces ? Array.from( contractStorages .get(contract.address!)! .pokeTraces.entries() ).map( (e) => e[1].receiver + ' ' + e[1].feedback + ' ' + e[0] + ',' ) : ''} | { console.log('e', e.currentTarget.value); setContractToPoke(e.currentTarget.value); }} placeholder="enter contract address here" /> |
2. Above the list of tokens, click the display options button:
3. Under **Filter by network**, expand **All Networks**.
4. Select **Shadownet**:
Now Temple shows your token balances on the Shadownet test network.
3. From your wallet, get the address of your account, which starts with `tz1`.
This is the address that applications use to work with your wallet.
4. Go to the Shadownet faucet page at https://faucet.shadownet.teztnets.com/.
5. On the faucet page, paste your wallet address into the input field labeled "Or fund any address" and click the button for the amount of tez to add to your wallet.
20 tez is enough to work with the tutorial application, and you can return to the faucet later if you need more tez.
It may take a few minutes for the faucet to send the tokens and for those tokens to appear in your wallet.
You can use the faucet as much as you need to get tokens on the testnet, but those tokens are worthless and cannot be used on Mainnet.

6. If you created a new account, initialize the account by sending any amount of tez to any other account.
Before the new account can use dApps, it must send at least one transaction to Tezos.
This first transaction reveals the public key that proves that transactions came from this account.
If your account is new, you can send 1 tez to any other account, including your own account, via your wallet application to reveal the account.
Now you have an account and funds that you can use in dApps.
## Connecting to the user's wallet
In this section, you add code to connect to the user's wallet with the Taquito `TezosToolkit` and octez.connect `BeaconWallet` objects.
Taquito accesses Tezos and octez.connect accesses wallets.
IMPORTANT: however you design your app, it is essential to use a single instance of the `BeaconWallet` object.
It is also highly recommended use a single instance of the `TezosToolkit` object.
Creating multiple instances can cause problems in your app and with Taquito in general.
This application keeps these objects in the `App.svelte` file because this is the only component in the application.
If you add more components, you should move these objects to a separate file to maintain a single instance of them.
1. In the `src/App.svelte` file, add these imports to the `
The address of the connected wallet is {address}.
Its balance in tez is {balance}.
To get tez, go to https://faucet.shadownet.teztnets.com/ .
{:else} {/if}
Then the application runs the `getWalletBalance` function, which gets the wallet's balance in tez tokens.
Because the Svelte component's variables changed, the application refreshes automatically and shows the wallet address, balance, and "Disconnect wallet" button:
If you click **Disconnect wallet**, the application goes back to its initial state.
Now the application can connect to user wallets.
In the next section, you add code to use the wallet to get the user's approval to send transactions to Tezos.
## Design considerations
Interacting with a wallet in a decentralized application is a new paradigm for many developers and users.
Follow these practices to make the process easier for users:
* Let users manually connect their wallets instead of prompting users to connect their wallet immediately when the app loads.
Getting a wallet pop-up window before the user can see the page is annoying.
Also, users may hesitate to connect a wallet before they have had time to look at and trust the application, even though connecting the wallet is harmless.
* Provide a prominent button to connect and disconnect wallets.
* Put the button in a predictable position, typically at the top right or left corner of the interface.
* Use "Connect" as the label for the button.
Avoid words like "sync" because they can have different meanings in dApps.
* Display the status of the wallet clearly in the UI.
You can also add information about the wallet, including token balances and the connected network for the user's convenience, as this tutorial application does.
Showing information about the tokens and updating it after transactions allows the user to verify that the application is working properly.
* Enable and disable functions of the application based on the status of the wallet connection.
For example, if the wallet is not connected, disable buttons for transactions that require a wallet connection.
Also, disable transaction buttons while transactions are pending to prevent users from making duplicate transactions.
# Part 3: Sending transactions
Now that the application can connect to the user's wallet, it can get the user's approval to send transactions to Tezos with that wallet.
## The tutorial smart contract
This decentralized application (or dApp) uses a *smart contract* on Tezos, which is a type of program that runs on a blockchain.
This contract behaves like an API, because your application calls its entrypoints to run commands.
In this case, the smart contract was deployed for the purposes of this tutorial, so it is not a full-featured application.
It does two things to simulate a bank:
* It accepts deposits of tez tokens that users send and records how many tokens they sent.
* It accepts a request to withdraw tez and sends them back to the user's wallet.
The contract has two *entrypoints* for these functions, named "deposit" and "withdraw."
These entrypoints are like API endpoints or functions in a program: clients can call them and pass parameters to them.
However, unlike API endpoints and functions, they do not return a value.
## Steps for sending transactions
Sending transactions with Taquito involves these general steps:
1. Create an object that represents the smart contract to call.
2. Disable UI elements related to the transaction to prevent the user from sending duplicate transactions.
3. Create the transaction, including specifying this information:
* The entrypoint to call
* The parameters to pass
* The amount of tez to pass, if any
* Maximum amounts for the fees for the transaction
4. Send the transaction to the user's wallet for approval.
5. Wait for the transaction to complete.
6. Update information about the user's wallet and other details in the UI based on the result of the transaction.
7. Enable UI elements that were disabled during the transaction.
## Making a deposit transaction
Follow these steps to set up the application to send transactions to the deposit entrypoint:
1. In the `App.svelte` file, add the address of the contract as a constant with the other constants in the `
The address of the connected wallet is {address}.
Its balance in tez is {balance}.
To get tez, go to https://faucet.shadownet.teztnets.com/ .
Deposit tez:
Withdraw tez:
{:else} {/if}