Typescript SDK

Let's generate a Typescript SDK for KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of and interact with it. See section SDK generation for the details about this contract. The Typescript SDK relies on the Taquito library for forging and signing operations.

Import a KT1 from the Tezos blockchain

To generate the SDK of the contract in the current directory, run:

factori import kt1 . KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of \
    --typescript \
    --name my_contract \
    --network ghostnet \

Compile deps and SDK

You will need to have Node installed.

Then you want to install the necessary Typescript dependencies, compile your SDK, and cleanly format the generated code:

make ts-deps
make format-ts # optional but recommended
make ts

You are ready to use the Typescript SDK!

Hello world example

First, you may want to have a look at the content of src/typescript_sdk/src/ directory.

ls src/typescript_sdk/src/

Create a file src/typescript_sdk/src/test.ts with the following content:

import * as C from "./my_contract_interface"
import * as functolib from "./functolib"
import {
  } from "@taquito/taquito"

var config = functolib.ghostnet_config;

const tezosKit = new TezosToolkit(config.node_addr)
const debug = false

async function main(tezosKit: TezosToolkit){
    functolib.setSigner(tezosKit, functolib.alice_flextesa.sk);
    let hello_kt1 = "KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of"
    let res = await C.call_hello(tezosKit, hello_kt1, "Hello from typescript", 0, "", true);
    console.log("Operation sent to a node. Its hash is: " + res.hash);
    console.log("Check its status: https://ghostnet.tzkt.io/" + res.hash);
    // TODO: Add a await inclusion here.


Recompile with

make ts

Run with

node src/typescript_sdk/dist/test.js

If everything goes well, you should see your transaction at: https://ghostnet.tzkt.io/KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of

Quick Deploy

If you want to quickly re-originate the contract, you can run

factori deploy --typescript --network ghostnet --storage blockchain my_contract

This will deploy the contract on Ghostnet, using Flextesa's Alice account, and with as initial storage the storage on the blockchain at the moment of importation.


If you run into the error

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)

when using JSON.stringify in your code, the file functolib.ts exports a variable JSONbig which has a stringify method that will solve this error (thanks to the json-bigint library). You can hence simply use JSONbig.stringify.

Note that, if no language is specified, the SDK generated by Factori is the Typescript one.