Crates.io | pchain_compile |
lib.rs | pchain_compile |
version | 0.4.3 |
source | src |
created_at | 2023-07-12 04:00:05.06208 |
updated_at | 2024-04-11 10:37:57.40421 |
description | ParallelChain Smart Contract Compile CLI - A command line tool for compiling ParallelChain Smart Contract. |
homepage | |
repository | https://github.com/parallelchain-io/pchain-compile |
max_upload_size | |
id | 914259 |
size | 170,661 |
pchain_compile
is a command line tool for reproducibly building Rust code into compact, gas-efficient WebAssembly ParallelChain Mainnet Smart Contracts.
pchain_compile
compiles the ParallelChain smart contract code from Rust into a WebAssembly binary. To know more about developing ParallelChain smart contracts, visit ParallelChain Mainnet Contract SDK.
By default, the compiler requires docker to be installed in your local machine. In detail, it pulls the Docker Image from DockerHub, and starts a docker container which provides a complete environment for building WebAssembly binary. To install docker, follow the instructions in Docker Docs.
Download prebuilt executables from the Github Releases page.
Alternatively, you can install the binary crate pchain_compile by cargo install if Rust has been installed already.
cargo install pchain_compile
Let's say your smart contract source code is in the folder contract
under your home directory.
/home/
|- user/
|- contract/
|- src/
|- lib.rs
|- Cargo.toml
Run pchain_compile
with the arguments source and destination to specify the folder of the source code and the folder for saving the result.
pchain_compile build --source /home/user/contract --destination /home/user/result
Once complete, the console displays message:
Build process started. This could take several minutes for large contracts.
Finished compiling. ParallelChain Mainnet smart contract(s) ["contract.wasm"] are saved at (/home/user/result).
Your WebAssembly smart contract is now saved with file extension .wasm
at the destination folder.
If you are running on Windows, here is the example output:
$ .\pchain_compile.exe build --source 'C:\Users\user\contract' --destination 'C:\Users\user\result'
Build process started. This could take several minutes for large contracts.
Finished compiling. ParallelChain Mainnet smart contract(s) ["contract.wasm"] are saved at (C:\Users\user\result).
To understand more about the commands and arguments, run pchain_compile build --help
.
pchain_compile
Docker Imagepchain_compile
pulls a docker image from ParallelChain Lab's official DockerHub repository for the build process. The docker image provides an environment with installed components:
There are different tags of the docker image. They vary on the versions of the components. The table below describes the tags and their differences.
Image Tag | rustc | wasm-snip | wasm-opt |
---|---|---|---|
0.4.3 | 1.77.1 | 0.4.0 | 114 |
0.4.2 | 1.71.0 | 0.4.0 | 114 |
mainnet01 | 1.66.1 | 0.4.0 | 109 |
To build a smart contract in a specific docker environment, run with argument use-docker-tag. For example,
pchain_compile build --source /home/user/contract --destination /home/user/result --use-docker-tag 0.4.3
If use-docker-tag is not used, the docker image tag is determined by the version of pchain_compile
. For example, pchain_compile
v0.4.3 will pull the docker image with tag 0.4.3
.