Skip to main content
Version: 20.0.0

Smart contract collection

The contracts used in Taquito Integration Tests and in Taquito Documentation Live Code Examples are test data and require curation. Here we collect the contracts, give them names, demonstrate their properties and describe their use.

Each contract description will include the storage in Michelson and the storage as Javascript as used by Taquito.

Basic Contracts

IncrementContract

This contract serves as the default introductory example on the Ligo-WEB-IDE It has two endpoints, %decrement and %increment. The contract is used to demo addition and subtraction by a smart contract. This contract has neither an FA1.2 nor an FA2 interface.

Entrypoints:

  • decrement
  • increment
storage int

MichelsonMapContract

The contract supports a Michelson Tutorial. It has a default endpoint that takes a pair of an address and an amount of tez.

Entrypoints:

  • default
storage (map address mutez);

GenericMultisigContract

This contact has a stored counter. The contract is used in some Taquito Integration Tests for generic tests of such features as transfers.

Entrypoints:

  • default
  • main
storage (pair (nat %stored_counter) (pair (nat %threshold) (list %keys key)));

Lambda Contracts

Taquito internally contains a list of lambda contracts. Thus, there is no need to deploy a lambda contract if you are using Mainnet, Ghostnet or another testnet. Taquito will detect the current network and use the appropriate lambda contract.

Lambda views are introduced in Tzip4.

LambdaViewContract

Not a supported FA1.2 contract. Almost an Fa2 interface but it is missing update_operators.

Entrypoints:

  • approve
  • getAllowance
  • getBalance
  • getTotalSupply
  • mint
  • transfer
storage (pair
(pair
(big_map %ledger address (pair (map %allowances address nat) (nat %balance)))
(address %owner))
(nat %totalSupply));

LambdaViewWithTokenContract

This contact is another example of a Lambda contract, this time involving a token. It is not a supported FA1.2 contract. The contract does have the three entry points that define an FA2 interface - .

Entrypoints:

  • balance_of
  • token_metadata_registry
  • transfer
  • update_operators
storage (pair
(pair
(big_map %ledger address (pair (set %allowances address) (nat %balance)))
(big_map %token_metadata nat
(pair (nat %token_id)
(pair (string %symbol)
(pair (string %name)
(pair (nat %decimals)
(map %extras string string)))))))
(nat %total_supply));

Contracts with Maps

MapWithPairasMapContract

A simple contract with a default entrypoint that takes unit. Not a supported FA1.2 contract.

The contract is used to demonstrate the get method of the MichelsonMap class, which accesses values of the map for a specified key. If the storage does not annotate its properties, the caller must use numeric indexes instead. This contract does not annotate the pairs of the key pair either so numeric indexes are used for this also.

Entrypoints:

  • default
storage (pair
(pair (address %theAddress)
(map %theMap (pair nat address) (pair (mutez %amount) (int %quantity))))
(int %theNumber));

MapWithComplexKeysContract

This contract has a single default entrypoint that takes unit and produces a map:

Pair 10 (Pair 20 (Pair "Hello" (Pair 0xffff (Pair 100 (Pair False (Pair "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" (Pair 1570374509 "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")))))))

The get method of the MichelsonMap class accesses values of the map for a specified key.

Entrypoints:

  • default
storage (map
(pair int
(pair nat
(pair string
(pair bytes
(pair mutez
(pair bool
(pair key_hash (pair timestamp address))))))))
int);

Note the lack of annotations in the Michelson for the storage. If the storage does not annotate its properties, the caller must use numeric indexes instead, as the Taquito javascript shows.

MapWithInitialStorageContract

Taquito provides a get method of the MichelsonMap on storage of type Map. We can only change contract storage by calling the function provided by the contract. The main function on this Smart Contract is decreasing the value of the current_stock associated with the key 1.

Entrypoints:

  • default
storage (map nat (pair (nat %current_stock) (mutez %max_price)));

MapWithMapandBigmapContract

The get method of the MichelsonMap class accesses the values of the map and values of the bigMap. The difference is that the value gets returned directly for a map while the get method on a bigMap returns a promise.

Entrypoints:

  • default
storage (pair (big_map %thebigmap (pair nat address) int)
(map %themap (pair nat address) int));

Contracts with BigMaps

BigMapsMultipleValuesContract

This contract has an FA1.2 interface.

It is possible to fetch multiple big map values using Taquito with one call using the getMultipleValues method of the BigMapAbstraction class. Taquito will ensure that all fetched big maps come from the same block to ensure a consistent state.

Entrypoints:

  • approve
  • burn
  • getAdministrator
  • getAllowance
  • getBalance
  • getTotalSupply
  • mint
  • setAdministrator
  • setPause
  • transfer
storage (pair (big_map address (pair nat (map address nat)))
(pair address (pair bool nat)));

BigMapsComplexStorageContract

This contract is used in many Taquito documentation Live Code Examples to demonstrate how to get data from a complex storage. Not a supported FA1.2 contract.

The storage uses a pair composed of a nested pair and a map (annotated as %validators). The nested pair consists of an address (annotated as %owner) and a bigMap (annotated as %records). The map %validators use a natural number (nat) as its key and address its value. The bigMap %records uses a value in bytes as its key and a pair consisting of nested pairs as its value. We find addresses and natural numbers in these nested pairs, where some are optional, and a map (annotated %data). The map %data uses a string as its key, and the user needs to choose the value of the map between different proposed types (int, bytes, bool, ...).

Entrypoints

  • admin_update
  • resolve
  • set_child_record
  • update_record
storage (pair
(pair (address %owner)
(big_map %records bytes
(pair
(pair
(pair (option %address address)
(map %data string
(or
(or
(or
(or (address %address)
(bool %bool))
(or (bytes %bytes)
(int %int)))
(or
(or (key %key)
(key_hash %key_hash))
(or (nat %nat)
(signature %signature))))
(or
(or (string %string)
(mutez %tez))
(timestamp %timestamp)))))
(pair (address %owner) (option %ttl nat)))
(option %validator nat))))
(map %validators nat address));

BigMapsWithLedgerContract

This contract is used in Taquito integration tests. It is not a FA1.2 contract, since Entrypoint "transfer" has type (pair (pair (address %0) (address %1)) (nat %2)), but should have type (pair address address nat). Also not an FA2 contract as it does not have an entrypoint for update_operators.

Entrypoints

  • approve
  • burn
  • getAllowance
  • getBalance
  • getTotalSupply
  • mint
  • setOwner
  • setPause
  • transfer
storage (pair
(pair
(big_map %ledger address (pair (map %allowances address nat) (nat %balance)))
(address %owner))
(pair (bool %paused) (nat %totalSupply)));

BigMapPackContract

By default, a call to an RPC node is used to pack data when fetching values from a big map. Big map keys need to be serialized or packed and Taquito relies on the PACK functionality of a Tezos RPC node to pack the big map keys. This may be considered inefficient as it adds a request to a remote node to fetch data.

Now, Taquito allows you to pack the required data locally to fetch values from a big map. By relying on the local pack implementation, Taquito eliminates one RPC roundtrip when fetching big map values.

This contract is for demonstrating packing. Not a supported FA1.2 contract.

Entrypoints

  • default
storage (pair nat (big_map nat string));

On Chain Views Contracts

Views are meant to be called by a contract using the Michelson Instruction View followed by the view name and its result type. See TaquitoDocs for more details.

ContractCallFib

This contract is used to demonstrate On Chain views. It calls the view 'fib' in another contract called contractTopLevelViews.

Entrypoints

  • default
storage nat

ContractTopLevelViews

This contract has a series of views which are sections of Michelson Code, for example:

view "add" nat nat { UNPAIR ; ADD } ;

which can be called by other contracts to calculate and return some value.

Entrypoints

  • default
storage nat

Tzip-7 Contracts

Tzip-7 introduced the approvable ledger: Tzip-7

TokenContract

This contract has an FA1.2 interface. To determine if a contract has an FA1.2 interface we can use

tezos-client check contract KT1CfFBaLoUrgv93k8668KCCcu2hNDNYPz4L implements fa1.2

Entrypoints:

  • approve
  • burn
  • getAdministrator
  • getAllowance
  • getBalance
  • getTotalSupply
  • mint
  • setAdministrator
  • setPause
  • transfer
storage (pair (big_map address (pair nat (map address nat)))
(pair address (pair bool nat)));

Tzip-12 Contracts

The @taquito/tzip12 package allows retrieving metadata associated with tokens of an FA2 contract. You can find more information about the TZIP-12 standard here.

A contract has an FA2 interface if it has entrypoints: transfer, balance_of, and update_operators

Tzip12BigMapOffChainContract

This contract has an FA2 interface.

Entrypoints:

  • balance_of
  • mint
  • mutez_transfer
  • set_administrator
  • set_metadata
  • set_pause
  • transfer
  • update_operators
storage (pair
(pair (address %administrator)
(pair (nat %all_tokens) (big_map %ledger (pair address nat) nat)))
(pair
(pair (big_map %metadata string bytes)
(big_map %operators
(pair (address %owner) (pair (address %operator) (nat %token_id)))
unit))
(pair (bool %paused)
(big_map %tokens nat
(pair (map %metadata_map string bytes)
(nat %total_supply))))));

Tzip-16 Contracts

The @taquito/tzip16 package allows retrieving metadata associated with a smart contract. These metadata can be stored on-chain (tezos-storage) or off-chain (HTTP(S) or IPFS). The package also provides a way to execute the MichelsonStorageView found in the metadata. More information about the TZIP-16 standard can be found here.

The getMetadata method returns an object which contains the URI, the metadata in JSON format, an optional SHA256 hash of the metadata and an optional integrity check result.

A sequence diagram can be found here.

Each of the following contracts is used to demonstrate an aspect of getMetadata.

Tzip16StorageContract

In this example the storage holds the metadata in a bigmap.

Entrypoints:

  • default
storage (pair (big_map %metadata string bytes)
(map %taco_shop_storage nat (pair (nat %current_stock) (mutez %max_price))));

Tzip16HTTPSContract

In this example the storage holds a URL that refers to the metadata.

Entrypoints:

  • default
storage (pair (big_map %metadata string bytes)
(map %taco_shop_storage nat (pair (nat %current_stock) (mutez %max_price))));

Tzip16SHA256Contract

In this example the storage holds a URL encrypted with SHA 256 that refers to the metadata.

Entrypoints:

  • default
storage (pair (big_map %metadata string bytes)
(map %taco_shop_storage nat (pair (nat %current_stock) (mutez %max_price))));

Tzip16IPFSContract

In this example the storage holds an IPFS location that refers to the metadata.

Entrypoints:

  • default
storage (pair (big_map %metadata string bytes)
(map %taco_shop_storage nat (pair (nat %current_stock) (mutez %max_price))));

Tzip16OffChainContractJSON

This contract has a view named someJson that can be found in the metadata. When we inspect those metadata, we can see that this view takes no parameter and has a returnType of bytes.

Entrypoints:

  • default
storage (pair nat (big_map %metadata string bytes));

Tzip16OffChainContractMultiply

This contract has a view named multiply-the-nat-in-storage that can be found in the metadata. When we inspect those metadata, we can see that this view takes a nat has a parameter, has a returnType of nat and has the following instructions: DUP, CDR, CAR, SWAP, CAR, MUL.

Entrypoints:

  • default
storage (pair nat (big_map %metadata string bytes));

WalletContract

Transactions to smart contracts operate in the same fashion as transactions to an implicit account, the only difference being the KT1... address. You will also receive a transaction hash and have to wait for the transaction to be confirmed. Once confirmed, it can be the right time to update the user's/contract's balance, for example.

Sending a transaction to a smart contract to update its storage will be a different type of action as it implies targetting a specific entrypoint and formatting correctly the data to be sent.

Fortunately, Taquito will make this operation go like a breeze! First, you need the contract abstraction created with the address of the smart contract you are targeting:

const contract = await Tezos.wallet.at('KT1B4WtE3MSEjGKnucRL5xhqnXCEX1QkLGPx');

This line creates a contract abstraction with multiple methods named after the contract entrypoints. For example, if you have a transfer entrypoint in your contract, you will also have a .transfer() method in the contract object. Each method accepts parameters required by the contract entrypoint.

For more details see Taquito Wallet API doc

Entrypoints:

  • default
storage int

WalletAreYouThereContract

This is a simple smart contract with two methods: areYouThere expects a value of type boolean to update the areYouThere value in the storage of the same type, and addName expects a value of type string to add it to the map in the contract.

Entrypoints:

  • addName
  • areYouThere
  • changeMessage
  • decrement
  • increment
storage (pair (pair (bool %areyouthere) (int %integer))
(pair (string %message) (map %names address string)));

SaplingContract

Sapling is a protocol enabling privacy-preserving transactions of fungible tokens in a decentralised environment. The example contract used in Taquito Integration Tests is a single-state sapling contract. It features the Michelson instruction "SAPLING_VERIFY_UPDATE". A sapling_state is represented by an integer value in the contract storage.

Entrypoints:

  • default
storage (sapling_state 8)

Chart of Smart Contract Properties

TypeInterface?MetadataDefault Endpoint
IncrementContractBasic
MichelsonMapContractBasicdefault
LambdaViewContractLambda
LambdaViewWithTokenContractLambdaFA2
MapWithWithSingleMapForStorageMapsdefault
MapWithPairasMapContractMapsdefault
MapWithComplexKeysContractMapsdefault
MapWithInitialStorageContractMapsdefault
BigMapsMultipleValuesContractBigMapsFA1.2
BigMapsComplexStorageContractBigMaps
BigMapPackContractBigMapsdefault
Tzip12BigMapOffChainContractTzip-12metadata
Tzip16StorageContractTzip-16metadatadefault
Tzip16HTTPSContractTzip-16metadatadefault
Tzip16SHA256ContractTzip-16metadatadefault
Tzip16IPFSContractTzip-16metadatadefault
Tzip16OffChainContractOneTzip-16metadatadefault
Tzip16OffChainContractTwoTzip-16metadatadefault
WalletContractWalletdefault
WalletAreYouThereContractWallet
TokenContractTokenFA2
KnownSaplingContractSaplingdefault

Provide detailed feedback