@tezwell/smartts-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.9.2 • Public • Published

SmartTS SDK

CI Coverage Status

SmartTS SDK is a metaprogramming framework for building Tezos smart contracts from Javascript. It uses the SmartPy compiler.



General Documentation

API Documentation (TypeDoc)



Using the package

Build and compile a contract

const { Equal, Contract, EntryPoint,GetSender, NewVariable, Require, SetValue, TNat, ContractStorage, GetVariable, Address, Nat, String } = require('@tezwell/smartts-sdk');
const SmartML = require('@tezwell/smartts-sdk/compiler');

const contract = new Contract()
    .setStorage(Nat(0))
    .addEntrypoint(
        new EntryPoint('ep1').setInputType(TNat()).code((arg) => [
            // Define a variable named "an_address"
            NewVariable('an_address', Address('KT1R9M3MDffw7qSVSnbJs46aMC9YzzZz3aGT')),
            // Require sender to be equal to variable "an_address", otherwise fail with "Not Admin!"
            Require(Equal(GetVariable('an_address'), GetSender()), String('Not Admin!')),
            // Replace the storage value with entry point argument
            SetValue(ContractStorage(), arg),
        ]),
    );

SmartML.compileContract(contract);
// Result:
//    {
//        micheline: 'parameter ...; storage ...; code { ... };',
//        json: [
//          { prim: 'storage', args: [...] },
//          { prim: 'parameter', args: [...] },
//          { prim: 'code', args: [...] },
//        ]
//    }

Build and compile a lambda

const { Comparison, Lambda, If, Return, String, Nat } = require('@tezwell/smartts-sdk');
const SmartML = require('@tezwell/smartts-sdk/compiler');

// A Lambda that returns "YES" if the argument is greater than or equal to Nat(10), returns "NO" otherwise.
const lambda = Lambda()
    .code((arg) => [
        If(Comparison.GreaterThanOrEqual(arg, Nat(10)))
            .Then([Return(String('YES'))])
            .Else([Return(String('NO'))]),
    ]);

SmartML.compileValue(lambda);
// Result:
//    {
//        micheline: '{ PUSH nat 1; SWAP; COMPARE; GE; IF { PUSH string "YES" } { PUSH string "NO" } }',
//        json: [
//            {
//                prim: "PUSH",
//                args: [
//                    {
//                        prim: "nat"
//                    },
//                    {
//                        int: "10"
//                    }
//                ]
//            },
//            {
//                prim: "SWAP"
//            },
//            {
//                prim: "COMPARE"
//            },
//            {
//                prim: "GE"
//            },
//            {
//                prim: "IF",
//                args: [
//                    [
//                        {
//                            prim: "PUSH",
//                            args: [
//                                {
//                                    prim: "string"
//                                },
//                                {
//                                    string: "YES"
//                                }
//                            ]
//                        }
//                    ],
//                    [
//                        {
//                            prim: "PUSH",
//                            args: [
//                                {
//                                    prim: "string"
//                                },
//                                {
//                                    string: "NO"
//                                }
//                            ]
//                        }
//                    ]
//                ]
//            }
//        ]
//    }

About

Project was supported by Tezos Foundation.

Package Sidebar

Install

npm i @tezwell/smartts-sdk

Weekly Downloads

0

Version

0.9.2

License

MIT

Unpacked Size

4.64 MB

Total Files

75

Last publish

Collaborators

  • romarq