Skip to main content
Version: 19.0.0

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://ghostnet.ecadinfra.com');
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 equivalent 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

Originate multiple contracts using Taquito

It is also possible to use Taquito to originate multiple contracts in one operation. The origination operations must be batched with the Batch API and after the contracts have been originated, the addresses will be available in an array returned by the getOriginatedContractAddresses method of the operation object:

const batch = Tezos.contract
.batch()
.withOrigination({
balance: '1',
code: CODE_1,
storage: 0,
})
.withOrigination({
balance: '2',
code: CODE_2,
storage: 0,
});
const op = await batch.send();
await op.confirmation();
const addresses = op.getOriginatedContractAddresses();

Provide detailed feedback