0.9.2 • Published 2 years ago

@tezwell/smartts-sdk v0.9.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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.

0.9.2

2 years ago

0.9.1

2 years ago

0.8.8

2 years ago

0.8.6

2 years ago

0.9.0

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.7.9

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.7.4

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.3

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.5.4

2 years ago

0.3.6

2 years ago

0.6.2

2 years ago

0.5.3

2 years ago

0.3.5

2 years ago

0.5.5

2 years ago

0.5.0

2 years ago

0.3.2

2 years ago

0.4.0

2 years ago

0.6.1

2 years ago

0.5.2

2 years ago

0.3.4

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.3.3

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

2 years ago

0.1.25

2 years ago

0.1.26

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.16

2 years ago

0.1.8

2 years ago

0.1.17

2 years ago

0.1.7

2 years ago

0.1.19

2 years ago

0.1.9

2 years ago

0.3.1

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago