Originating (Deploying) Contracts

Taquito can originate (create or deploy) Smart Contracts to the Tezos Blockchain.

Example demonstrating origination of a contract

In this example, we will originate the popular mutli-sig contract that is available here.

Since version 6.3.2, Taquito allows encoding and decoding between "plain" Michelson and JSON Michelson. The origination of Smart Contracts is now easier because it is no longer required to do the tezos-client command-line to convert & expand "plain" Michelson to JSON Michelson. You can now pass JSON Michelson as well as "plain" Michelson using the code parameter of the originate method.

Originate the contract using Taquito

Here are three examples of originating a contract using Taquito. The first example initializes the storage of the contract using a familiar-looking javascript object. The second and third demonstrates the use of plain Michelson and JSON Michelson. The first method is preferred, but if you have a reason to circumvent the convenient storage API, this allows you to do so.

These three examples will be shown using the Contract API and the Wallet API. The new Taquito Wallet API is designed to interact with wallets, and it supports Beacon, the TZIP-10 standard.

Note : To run the Wallet API examples, you can install a wallet extension to your browser. For example, the Beacon Extension can be download here.

This requires a signer to be configured, ie:

import { importKey } from '@taquito/taquito-signer';
importKey("p2sk2obfVMEuPUnadAConLWk7Tf4Dt3n4svSgJwrgpamRqJXvaYcg1")

a. Initializing storage using a Plain Old JavaScript Object

You can pass your initial storage as a JavaScript object to the storage: property. Taquito will encode your JavaScript object into a Michelson expression.

This JavaScript object :

{ stored_counter: 0,
threshold: 1,
keys: ['edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t'] }

Is equivilent to this Michelson expression :

(Pair 0 (Pair 1 { "edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t" }))

As you can see, the property names are discarded. The order of your properties is crucial!

Live Editor
Result

b. Initializing storage using a plain Michelson Expression for initial storage

When using Michelson expression for initial storage, we need to use the init parameter instead of the storage object.

Live Editor
Result

c. Initializing storage using a JSON encoded Michelson Expression for initial storage

Live Editor
Result