# A simple fund contract in LIGO

This tutorial guides you through developing, originating, and interacting with a simple decentralized fund smart contract on Tezos.

The origination and the interaction with the contract for tutorial purposes is done on Ithacanet, which is a testnet.

The simple fund contract does the following:

  • The contract can be funded in any amount of tez by anyone on the network.
  • 1 tez at a time can be withdrawn from the funded contract by anyone on the network.

# Prerequisites

# Overview

To get from zero to a deployed contract on Ithacanet, do the following:

  1. With Chainstack, create a public chain project.
  2. With Chainstack, join Ithacanet.
  3. With Chainstack, access your Tezos node credentials.
  4. Fund your developer Tezos account through a faucet (opens new window).
  5. With LIGO, create the contract.
  6. With the Tezos client, compile and originate the contract through your Tezos node.
  7. With the Tezos client, fund the contract.
  8. Fund your user Tezos account through a faucet and add the account to your Temple wallet.
  9. With Temple wallet, interact with the contract.

# Step-by-step

# Create a public chain project

See Create a project.

# Join Ithacanet

See Join a public network.

# Get your Tezos node access and credentials

See View node access and credentials.

# Install LIGO

See LIGO: Installation (opens new window).

# Install and configure the Tezos client

To install the client, see Tezos Client Installation and Setup (opens new window).

Once installed, configure the client to the Chainstack-deployed Ithacanet node:

tezos-client --endpoint ENDPOINT config update



tezos-client --endpoint https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d config update

# Fund your account with testnet tez

The Tezos faucet (opens new window) generates an account on Ithacanet with test tez.

  1. Go to the faucet (opens new window).
  2. Click Get Ithacanet tez.
  3. Download the generated JSON file.
  4. Place the generated JSON file in your project directory where the Tezos client is installed.
  5. Activate the funded account on Ithacanet:
tezos-client activate account ALIAS with "ACCOUNT_JSON"


  • ALIAS — any alias to call your account.
  • ACCOUNT_JSON — the account details in a JSON file that you downloaded from the faucet.


tezos-client activate account trent with "ithacanet.json"

Check the account balance:

tezos-client get balance for ALIAS


  • ALIAS — the alias you provided when activating the account.


tezos-client get balance for trent

# Create the contract

Create a simple fund contract in the PascaLIGO syntax with two entrypoints:

  • Deposit — any account on the network can deposit any amount of tez in the contract.
  • Withdraw — any account on the network can withdraw 1 tez at a time from the contract.

Create a file called simplefund.ligo:

// Two entrypoints: deposit any, withdraw 1 tez.
type entry is 
| Deposit
| Withdraw

// Simple storage in tez.
type storage is record  
 [balance: tez;    

const noOperations: list(operation) = nil;
const withdrawAmount : tez = 1tez;
const receiver: contract(unit) = Tezos.get_contract(Tezos.get_sender());
const payoutOperation: operation = Tezos.transaction(unit, withdrawAmount, receiver);
const operations : list (operation) = list [payoutOperation];

// Amend the storage balance with the deposited amount.
function depositAny(var storage: storage): (list(operation) * storage) is
  block {
        storage.balance := storage.balance + Tezos.get_amount();       
  with(noOperations, storage)

// Withdraw 1 tez at a time.
// 1 tez is sent to the sender calling the withdraw function.
function withdrawFixed(var storage: storage): (list(operation) * storage) is
  block {     
    storage.balance := Option.unopt(storage.balance - withdrawAmount);              
  } with(operations, storage)

function main(const action: entry; var storage: storage): (list(operation) * storage) is
  block {
  } with case action of [
    | Deposit(_param) -> depositAny(storage)
    | Withdraw(_param) -> withdrawFixed(storage)

# Test the contract

Before compiling the contract, you can test it using the LIGO CLI.

Deposit 10 tez:

$ ligo run dry-run simplefund.ligo --syntax pascaligo --amount 10 --entry-point  main "Deposit(unit)" "0"
( LIST_EMPTY() , record[balance -> 10000000mutez] )

Withdraw 1 tez:

$ ligo run dry-run simplefund.ligo --syntax pascaligo --entry-point main "Withdraw(unit)" "10000000mutez"
( CONS(Operation(0135a1ec49145785df89178dcb6e96c9a9e1e71e0a00000001c0843d0000663549d0f7c76252056ed0600da097a3e713237a00) ,
       LIST_EMPTY()) ,
  record[balance -> 9000000mutez] )

# Compile the contract

Compile the contract and save the compiled code in a .tz file:

ligo compile contract simplefund.ligo --entry-point main > simplefund.tz

You are now ready to originate the compiled contract on Ithacanet.

# Originate the contract

Originate the contract using your alias account, initiate the contract with 0 tez and provide the origination fee with --burn-cap:

tezos-client originate contract simplefund transferring 0 from ALIAS running simplefund.tz --init 0 --burn-cap 3


  • ALIAS — the account alias you activated previously.


tezos-client originate contract simplefund transferring 0 from trent running simplefund.tz --init 0 --burn-cap 3

Once the contract is originated, you will see the contract address in Originated contracts.


New contract KT1Nf431i6NKV9exNaxSNvKNcMA63F6VC3P4 originated.

You now have a working contract on Ithacanet.

Write down the contract address as you will need it later to interact with it through a web app and the Temple wallet.

# Interact with the contract using the Tezos client

You can now fund the contract using the Tezos client.

Get the contract parameter for the deposit function to pass to the Tezos client.

Get the parameter for Deposit:

$ ligo compile parameter simplefund.ligo --syntax pascaligo --entry-point main "Deposit(unit)"
(Left Unit)

Deposit 10 tez from your alias account to the contract:

tezos-client transfer 10 from ALIAS to simplefund --arg "(Left Unit)" --burn-cap 1


  • ALIAS — the account alias you activated previously.


tezos-client transfer 10 from trent to simplefund --arg "(Left Unit)" --burn-cap 1

Once the operation is included in a block, check the contract balance by querying the storage:

$ tezos-client get contract storage for simplefund

# Get a Temple wallet account with test tez

You need an account in the Temple wallet with some test tez to execute operations on Ithacanet.

  1. Install the Temple wallet (opens new window).
  2. Go to the faucet (opens new window).
  3. Click Get Ithacanet tez.
  4. Download the generated JSON file.
  5. In your Temple wallet instance, click Import account.
  6. Select Faucet File.
  7. Provide the JSON file you have downloaded.

The Temple wallet will activate your account with test tez.

# Interact with the contract using the Temple wallet

  1. Navigate to the BCD explorer (opens new window).
  2. Click Ithacanet.
  3. In the search field, provide your originated contract address.
  4. On the contract page, click Interact.
  5. Click withdraw > Execute > Temple - Tezos Wallet.
  6. Click Confirm.

This will connect your account from the Temple wallet with the contract and withdraw 1 tez to the account.

# Conclusion

This tutorial guided you through the basics of creating a contract in LIGO and originating the contract on a Tezos network.

You were also able to interact with the contract through the CLI with the Tezos client and through a web app with the Temple wallet.

This tutorial uses testnet, however the exact same instructions and sequence will work on the mainnet as well.