2019-06-17 rust开发erc20

2022-05-13 08:27:53 浏览数 (1)

工程是老外现成的,wrc20-rust 难点是如何编译和运行,这里记录一下

1、下载代码

代码语言:javascript复制
git clone https://github.com/hugo-dc/wrc20-rust

2、编译

代码语言:javascript复制
make
cargo build-ewasm
error: no such subcommand: `build-ewasm`
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 101

可以看到直接错误,咨询作者得到方法

3、安装build-ewasm

参考build-ewasm

代码语言:javascript复制
cargo install chisel
cargo install wasm-snip
cargo install --git https://github.com/hugo-dc/cargo-build-ewasm.git

然后再次make,得到下面的结果:

代码语言:javascript复制
make
cargo build-ewasm

Building ewasm module...

Executing chisel...
Ruleset ewasm:
    remapimports: Translated
    trimexports: Translated
    verifyimports: OK
    verifyexports: OK
    repack: OK
Writing to file: target/wasm32-unknown-unknown/release/ewasm_token.wasm


Minifying bytecode (wasm-snip)... OK

Finished
wasm-opt -Oz -o target/wasm32-unknown-unknown/release/ewasm_token.wasm target/wasm32-unknown-unknown/release/ewasm_token.wasm
make: wasm-opt: Command not found
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 127

又缺个wasm-opt

4、安装wasm-opt

编译安装

代码语言:javascript复制
git clone https://github.com/WebAssembly/binaryen.git
cd binaryen
mkdir build
cd build
cmake ..
make
sudo make install

安装成功后,回到wrc20-rust的目录,继续make

代码语言:javascript复制
make
cargo build-ewasm

Building ewasm module...

Executing chisel...
Ruleset ewasm:
    remapimports: Already OK; not translated
    trimexports: Already OK; not translated
    verifyimports: OK
    verifyexports: OK
    repack: OK
Writing to file: target/wasm32-unknown-unknown/release/ewasm_token.wasm


Minifying bytecode (wasm-snip)... OK

Finished
wasm-opt -Oz -o target/wasm32-unknown-unknown/release/ewasm_token.wasm target/wasm32-unknown-unknown/release/ewasm_token.wasm

5、安装wasm32-unknown-unknown

可能出现错误:ERROR: error building wasm module, confirm target wasm32-unknown-unknown is installed 继续安装

代码语言:javascript复制
rustup target add wasm32-unknown-unknown

0 人点赞