npm.io
2.1.0 • Published 4 years ago

massa-sc-utils

Licence
MIT
Version
2.1.0
Deps
2
Size
28 kB
Vulns
0
Weekly
0

massa-sc-utils

Various utils for easily building smart contract

Requirements

  • NodeJS 14+
  • npm / yarn (see package.json)

Package commands

  1. Run yarn install to install all deps
  2. Run yarn run build to build distribution content
  3. Run yarn run test to run integration and unit tests
Smart contract utilities

The library provides methods for compiling smart contracts written in AssemblyScript with TypeScript, either via CLI or on the fly. With both methods, the returned values are a text, a binary and a base64 representation of the WASM.

Examples are shown below:

const SMART_CONTRACT_EXAMPLE = `export function add(x: number, y: number): number { return x+y };`;

const utils = new SmartContractUtils();

// compile smart contract from a typescript file with assemblycode
const compiledScFromSource: CompiledSmartContract = await utils.compileSmartContractFromSourceFile({
    smartContractFilePath: "helloworld.ts",
} as WasmConfig);

// compile smart contract from a .wasm file
const compiledScFromFile: CompiledSmartContract = await utils.compileSmartContractFromWasmFile("helloworld.wasm");

// compile smart contract on the fly
const compiledScFromString: CompiledSmartContract = await utils.compileSmartContractFromString(SMART_CONTRACT_EXAMPLE);

Keywords