Skip to content

DSiSc/wasm-cdt

Repository files navigation

wasm-cdt

justitita wasm contract development kit

Build Status codecov

Getting started

Running it then should be as simple as:

$ make all

Testing

$ make test

Build Docker Image

We use docker so that wasm-cdt command can run on any type system. You can compile from the source code or directly use pre-build binary to build docker image.

  1. Make build directory, structure:

     -\
       -llvm\
       -misc\
       -Dockerfile
       -wasm-cdt
    

    llvm: llvm binary files

    misc: base header files

    Dockerfile: Docker build file

    wasm-cdt: go build binary file.

  2. Start Building:

     $ docker build -t wasm-cdt .
     $ docker run –rm -it wasm-cdt --help (verify your image)
    

Write Wasm Contract

  1. For your C file must have invoke method, and invoke is the only entry point of the contract. invoke method format:

    $ char *invoke(int argc, char *argv[])
    
  2. You can use justitia.h in your contract to get info relate to chain:

    #include <stdio.h>
    #include <string.h>
    #include "justitia.h"
    
  3. demo.c is our demo contract, you get some detail to write wasm contract.

  4. To deploy a contract, you can use our deploy command.

    docker run --rm -it -v ${local_workspace}:/workspace wasm-cdt deploy -f ${wasm_file} -ac ${deploy_account} -ep ${endpoint_address}
    
  5. To call wasm contract, you can use our rpc api wasm-call and wasm-transaction.