|
| 1 | +# Quick Start Guide for DTVM_SolSDK |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +The fastest way to set up the compilation environment is to use a Docker image or build it based on the provided Dockerfile: |
| 6 | + |
| 7 | +```bash |
| 8 | +docker pull dtvmdev1/dtvm-sol-dev-x64:main |
| 9 | +``` |
| 10 | + |
| 11 | +Before using DTVM_SolSDK, ensure the following dependencies are installed on your system: |
| 12 | + |
| 13 | +- **LLVM 16** or **lld-16** |
| 14 | +- **solc** (Solidity compiler) or **Foundry** |
| 15 | +- **Binaryen** (Optional) |
| 16 | + |
| 17 | +### Installing LLVM 16 or lld-16 |
| 18 | + |
| 19 | +```bash |
| 20 | +cd /opt |
| 21 | +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.4/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz |
| 22 | +tar -xvf clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz |
| 23 | +rm -rf clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz |
| 24 | +mv clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04 llvm16 |
| 25 | +export LLVM_SYS_160_PREFIX=/opt/llvm16 |
| 26 | +export PATH=$LLVM_SYS_160_PREFIX/bin:/opt:$PATH |
| 27 | +``` |
| 28 | + |
| 29 | +### Installing Solidity Compiler (solc) |
| 30 | + |
| 31 | +Download the Solidity compiler from: |
| 32 | +[https://github.com/ethereum/solidity/releases](https://github.com/ethereum/solidity/releases) |
| 33 | + |
| 34 | +### Installing Foundry |
| 35 | + |
| 36 | +Install Foundry from: |
| 37 | +[https://getfoundry.sh/](https://getfoundry.sh/) |
| 38 | + |
| 39 | +## Basic Usage |
| 40 | + |
| 41 | +### Compiling a Solidity Contract to WebAssembly |
| 42 | + |
| 43 | +The compilation process involves two main steps: |
| 44 | + |
| 45 | +1. Compile Solidity to Yul IR using the Solidity compiler |
| 46 | +2. Compile Yul IR to WebAssembly using yul2wasm |
| 47 | + |
| 48 | +Here's a basic example: |
| 49 | + |
| 50 | +```bash |
| 51 | +# Step 1: Compile Solidity to Yul IR |
| 52 | +solc --ir --optimize-yul -o output_directory --overwrite your_contract.sol |
| 53 | + |
| 54 | +# Step 2: Compile Yul IR to WebAssembly |
| 55 | +yul2wasm --input output_directory/ContractName.yul --output your_contract.wasm |
| 56 | +``` |
| 57 | + |
| 58 | +### Command Line Options |
| 59 | + |
| 60 | +yul2wasm provides several command-line options: |
| 61 | + |
| 62 | +| Option | Description | |
| 63 | +|--------|-------------| |
| 64 | +| `--input <file>` | Specify the input Yul file (required) | |
| 65 | +| `--output <file>` | Specify the output WebAssembly file (required) | |
| 66 | +| `--verbose` | Enable verbose output for debugging | |
| 67 | +| `--debug` | Generate debug information | |
| 68 | +| `--opt-level <level>` | Set LLVM optimization level (0-3, default: 3) | |
| 69 | + |
| 70 | +### Output File Types |
| 71 | + |
| 72 | +When working with yul2wasm, you'll encounter several file types: |
| 73 | + |
| 74 | +- `.wasm`: WebAssembly binary format - the final compiled contract that can be deployed on Wasm-based blockchains |
| 75 | +- `.cbin`: Contract binary format - contains the compiled bytecode of the contract |
| 76 | +- `.cbin.hex`: Hexadecimal representation of the contract binary - useful for deployment and verification |
| 77 | + |
| 78 | +### Converting WebAssembly to Text Format (WAT) |
| 79 | + |
| 80 | +For inspection or debugging, you can convert the binary WebAssembly to text format: |
| 81 | + |
| 82 | +```bash |
| 83 | +wasm2wat -o your_contract.wat your_contract.wasm |
| 84 | +``` |
| 85 | + |
| 86 | +## Troubleshooting |
| 87 | + |
| 88 | +For common issues, security best practices, and more detailed information, please contact us through: |
| 89 | +[https://github.com/DTVMStack/DTVM_SolSDK/issues](https://github.com/DTVMStack/DTVM_SolSDK/issues) |
0 commit comments