GithubHelp home page GithubHelp logo

gfusee / mx-sdk-as Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 0.0 425 KB

AssemblyScript smart contract library designed for MultiversX's VM.

License: GNU General Public License v3.0

TypeScript 99.85% HTML 0.09% JavaScript 0.06%

mx-sdk-as's Introduction

MultiversX WASM AssemblyScript (Proof of concept)

A proof of concept to make MultiversX smart contracts in AssemblyScript.

⚠️ Warning ⚠️

THIS IS ONLY EXPERIMENTAL, DO NOT USE IT IN PRODUCTION !

The aim of this repo is to make a proof of concept and ONLY a proof of concept. The code is neither clean nor safe nor optimized !

Getting started

Tutorials

Two smart contracts tutorials are available here : https://fusee.gitbook.io/mx-sdk-as/.

They will give a good idea about what you can build with this framework.

AssemblyScript

AssemblyScript is nearly the same as Typescript, but there is still some differences, please check https://www.assemblyscript.org/ to have more informations.

Contract development

Build the empty contract

If you only want to try writing smart contracts with this framework do the following steps :

And you're done ! The contract is compiled into the build folder.

Feel free to check examples contracts inside the contracts/examples folder, these are reproduction of mx-sdk-rs examples contracts.

Test the contract via scenario

If you have a standard installation of mxpy, the run-scenarios executable should be located in the ~/multiversx-sdk/vmtools folder. Here are the steps to execute scenarios :

  • Compile the contract (steps above)
  • Find your run-scenario executable path inside your custom installation of mxpy installation
  • Inside the root folder of the project, run the <path to run> scenarios command

Documentation

There is currently no documentation, feel free to check examples inside the contract/examples folder.

If after that you have any question, feel free to DM me !

What's not (properly) working

Structs/classes & enums

Structs and enums are workings but with some limitations.

In order to create a classes which is compatible with the framework you should annotate it with either @struct or @enumType :

@struct
export class Human {
    name: ManagedBuffer
    age: ManagedU64
    wallet: ManagedAddress
}

or

@enumType
export enum Animal {
    Cat,
    Dog,
    Spider
}

You should be aware of the four following limitations :

  • Constructor should have no parameter. It is planned in the future to allow constructors with params, for now, you can use statics methods as a workaround.
  • They should have only managed properties types (those exported from this framework)
  • Enums are converted into classes at compilation. So switch statements may not work as expected, please use if instead.
  • They are allocated on the heap. More explanations below.

Async calls

MultiversX team will soon change the asynchronous contracts calls system, hence I will not implement the current system. This leads to several limitations like no call to ESDT proxy (issuing tokens, managing roles)

This feature will be my ultimate priority when MultiversX team will implement the new async calls system.

Statics and generics

There is a limitation related to Typescript, we cannot define static methods on interfaces so we cannot call them on generic parameters.

A good workaround is to instantiate dummy objects to have access to those methods. This may lead to useless VM calls, I'm hunting these useless calls to remove them.

Closures

AssemblyScript has a SEVERE limitation about closures. Inside a closure we cannot use a variable declared outside, for example this code works :

myBiguints.forEach(biguint => {
    if (biguint == BigUint.zero()) {
        throw new Error("BigUint should be greater than 0 !")
    }
})

But the following code does not work :

const sum = BigUint.zero()
myBiguints.forEach(biguint => {
    sum += biguint //does NOT compile because sum is declared outside the closure
})

This issue is known by the AssemblyScript and should be fixed in the future : AssemblyScript/assemblyscript#798

Heap allocations

The biggest limitation of AssemblyScript I'm facing is that classes does not act as C structs, they are always allocated on the heap and this lead to big issues. I used a heavy workaround for some classes (ManagedBuffer, BigUint, ...) but not for all classes because this take a lot of time to refactor all.

This issue is known by the AssemblyScript team : AssemblyScript/assemblyscript#2254

mx-sdk-as's People

Contributors

gfusee avatar

Stargazers

johnykes avatar  avatar Cristian Fodor avatar Alexandre Bermudez avatar Filip Manole avatar Alex Paduraru avatar Claudiu avatar Madalin Purece avatar Gauthier Chapon avatar keysemails avatar Lucas Willems avatar Levi Chimezie avatar Patric Gutersohn avatar Andrejs Agejevs avatar Julian.io avatar Lucian Mincu avatar Thomas avatar olim_sol avatar Iuga Mihai avatar Cioclea Doru Octavian avatar Andrei Băncioiu avatar Matthieu avatar Azerus (Tikapo) avatar Mihai Daniel Eremia avatar Frederic ZINGG avatar Clément Guérin avatar Micha Vie avatar

Watchers

Julian.io avatar  avatar

mx-sdk-as's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.