Skip to content

Javascript version of the Move language compiler, supports compiling Move code into Move bytecode in the browser.

License

Notifications You must be signed in to change notification settings

nangongamo/move-js

 
 

Repository files navigation

move-js

Javascript version of the move language compiler and disassemble

Features

  • Compiling move package into blob
  • Disassemble contract

Example

  • Compiling move package into blob example
import { WasmFs } from '@wasmer/wasmfs'
import { Git, MovePackage } from '@starcoin/move-js'

const startWasiTask = async () => {
    const wasmfs = new WasmFs()
    const git = new Git(wasmfs)

    await git.download("/data/starcoin-framework.zip", "/workspace/starcoin-framework")
    await git.download("/data/my-counter.zip", "/workspace/my-counter")

    const mp = new MovePackage(wasmfs, {
      packagePath: "/workspace/my-counter",
      test: false,
      alias: new Map([
        ["StarcoinFramework", "/workspace/starcoin-framework"]
      ]),
      initFunction: "0xABCDE::MyCounter::init"
    })
    
    await mp.build()

    const blobBuf = wasmfs.fs.readFileSync("/workspace/my-counter/target/starcoin/release/package.blob")
    const base64Data = blobBuf.toString("base64")
    console.log("my-counter blob:", base64Data)
}

startWasiTask()
  • Disassemble contract example
import { WasmFs } from '@wasmer/wasmfs'
import { Disassemble } from '@starcoin/move-js'

const startDisassembleTask = async (app: HTMLDivElement) => {
  const wasmfs = new WasmFs()

  const dp = new Disassemble(wasmfs)

  // Chain code
  const account_scripts = "you code"

  dp.disassemble("account_scripts", account_scripts, (ok: boolean, data: string) => {
    console.log(ok)
    console.log(data)
  })

  app.innerHTML = `
      <h1>view disassemble in console:</h1>
    `
}

const app = document.querySelector<HTMLDivElement>('#app')!
startDisassembleTask(app)

About

Javascript version of the Move language compiler, supports compiling Move code into Move bytecode in the browser.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 44.1%
  • Rust 43.2%
  • JavaScript 12.7%