Skip to content

TrustedDataFramework/smart-contract-rust-exmaple

Repository files navigation

rust 智能合约样板

准备工作

  1. 安装 rust 环境,包括 rustup, cargo, rustc https://www.rust-lang.org/tools/install
  2. 安装 wasm-pack https://rustwasm.github.io/wasm-pack/installer/
  3. npm install

编译运行

  1. 编译
wasm-pack build --target  web --no-typescript 
  1. 运行
# 手动构造 abi
vim ./pkg/hello_wasm_bg.abi.json

填充如下内容

[
  {
    "name": "init",
    "type": "function",
    "inputs": [
      {
        "name": "a",
        "type": "string"
      },
      {
        "name": "b",
        "type": "string"
      }
    ],
    "outputs": [
      {
        "type": "string"
      }
    ]
  },
  {
    "name": "echo0",
    "type": "function",
    "inputs": [
      {
        "type": "bytes"
      }
    ],
    "outputs": [
      {
        "type": "bytes"
      }
    ]
  },
  {
    "name": "echo1",
    "type": "function",
    "inputs": [
      {
        "type": "address"
      }
    ],
    "outputs": [
      {
        "type": "address"
      }
    ]
  },
  {
    "name": "echo2",
    "type": "function",
    "inputs": [
      {
        "type": "u256"
      }
    ],
    "outputs": [
      {
        "type": "u256"
      }
    ]
  },
  {
    "name": "balance",
    "type": "function",
    "inputs": [
      {
        "type": "address"
      }
    ],
    "outputs": [
      {
        "type": "u256"
      }
    ]
  }
]
light-server -s .

打开 localhost:4000/tests/index.html

About

smart contract rust example

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published