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 multi-sig contract available here.

Since version 6.3.2, Taquito allows encoding and decoding between "plain" Michelson and JSON Michelson. Smart Contracts' origination is now more straightforward than it was 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 and "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, you can do so.

We will show these three examples using the Contract API and the Wallet API. The new Taquito Wallet API interacts with wallets, supporting 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/signer';
import { TezosToolkit } from '@taquito/taquito';
const Tezos = new TezosToolkit('https://granadanet.api.tez.ie');
importKey(Tezos, "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 the 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