Skip to main content
Version: Next

Taquito 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

KT1NcdpzokZQY4sLmCBUwLnMHQCCQ6rRXYwS

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

KT1PAW3ghZyysrArcexyj6VUU7NZF8tHKoZR

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

KT1J5Vbek6SAgUStzb3HEMdrgRnMaanxNkNB

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

We can send contract address, view method, and parameters as its own "view" to a simple lambda contract that always fails. We refer to this method as a "lambda view." The result of invoking our always-failing lambda contract is an error from the blockchain.

That may not sound very useful, but the brilliant part is that the error we receive contains the information we requested! We can not incur a fee for requesting data or waiting for confirmation from the network to call view methods.

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

Lambda views are introduced in Tzip4.

LambdaViewContract

KT1LNMrk8orMQ85zbwK25996dPhDxfSicvKh

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

KT1Tf2JXZP8wXjdgndsgMKM1uW9M4CC5rbWL

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

KT1BhFn1n1h4HJCxaRvoWEHPcp5UpAYbH3XN

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

KT1Jykv4V9tWbdJVff1jLx9tEs54hE442EX2

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

KT1Xjhpt7EB4kZvoSaeYE4zi47wYcdMAuDjD

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

KT1JdWjaxKb9Qr8beactUzW9dEH5iDpUcXuF

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

KT1UuzwkGJEoFJGY2XV21NdJeJ4tgXWmfbGE

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

KT1CfFBaLoUrgv93k8668KCCcu2hNDNYPz4L

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

KT1Ds2LC3QqxVVqh95VdfxTmBsRZZBrh8Pgm

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

KT1HdxMWw1rYK8BkuSzW38KMHu3JHqD5UmLo

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.

KT1T8FPwfbfWK5ir7A5bj6coqttKwhwchdnD

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.

KT1KJbtwARB2w3yN5fRjBE6CXJh5t9Hbbbpv

Entrypoints

  • default
storage nat

Tzip-7 Contracts

Tzip-7 introduced the approvable ledger: Tzip-7

TokenContract

KT1KxMdSBa9ippgTWwU7d1FkzTF5CirUkcp4

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

KT1Gn8tB1gdaST4eTwZUqsNJTRLZU5a4abXv

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.

KT1Sw8tCxQLQQGBw8VNFjoJpESxRXjC5XEii

Entrypoints:

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

Tzip16HTTPSContract

KT1P8w7Xeobq4xSk4W2JTjfDgQHxkTeg9ftT

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

KT1KB3L4p27PsDs27n2E7ZY9fxVXewHDEbVP

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

KT1NP2ZVLxWaSBQryDzUujmdv27ubJWZRckv

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

KT1Vms3NQK8rCQJ6JkimLFtAC9NhpAq9vLqE

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

KT19rDkTYg1355Wp1XM5Q23CxuLgRnA3SiGq

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

KT1B4WtE3MSEjGKnucRL5xhqnXCEX1QkLGPx

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

KT1WeQJ34tL4mwVyPJHNCq9VsrGUgFdFEdNp

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)));

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