- 安装 rust 环境,包括 rustup, cargo, rustc https://www.rust-lang.org/tools/install
- 安装 wasm-pack https://rustwasm.github.io/wasm-pack/installer/
npm install
- 编译
wasm-pack build --target web --no-typescript
- 运行
# 手动构造 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