mirror of https://github.com/status-im/nimplay.git
Create docs section, with some basic entries.
This commit is contained in:
parent
264bb037a5
commit
cdc27d019c
38
README.md
38
README.md
|
@ -1,37 +1,17 @@
|
||||||
# Ethereum smart contracts in Nim
|
# Nimplay
|
||||||
|
|
||||||
Disclaimer: WIP
|
Disclaimer: WIP
|
||||||
|
|
||||||
This is a sample of how building eWASM contracts in Nim is possible.
|
Nimplay is Domain Specific Language for writing smart contracts in Ethereum, using the Nim macro system.
|
||||||
Requirements:
|
|
||||||
* clang 7.0 or later with WebAssembly support. Most likely has to be built manually.
|
|
||||||
* 32bit version of libc. On linuxes it is usually provided by the package manager.
|
|
||||||
* `wasm2wat` and `wat2wasm` from [wabt (WebAssembly binary toolkit)](https://github.com/WebAssembly/wabt). They need to be in the `PATH`.
|
|
||||||
* [optional] [wasm-gc](https://github.com/alexcrichton/wasm-gc) optimizer
|
|
||||||
|
|
||||||
## Compiling examples
|
## Language Principles
|
||||||
```
|
|
||||||
export WASM_LLVM_BIN=/path/to/llvm/bin/folder
|
|
||||||
nimble examples
|
|
||||||
```
|
|
||||||
|
|
||||||
## Troubleshooting
|
*to be decided ;)*
|
||||||
* **Emscripten doesn't work!** It is not expected to. Use clang with wasm target enabled.
|
|
||||||
* **clang is difficult to build.** No, it's easy. Follow these steps:
|
## Docs
|
||||||
```
|
|
||||||
tag=release_70
|
[Installation Docs](docs/installing.md) to get nimplay up and running.
|
||||||
INSTALL_PREFIX=$(pwd)/llvm-wasm
|
[Language Basics](docs/.md) to get with coding with nimplay.
|
||||||
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/llvm.git
|
|
||||||
cd llvm/tools
|
|
||||||
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/clang
|
|
||||||
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/lld
|
|
||||||
cd ..
|
|
||||||
mkdir build
|
|
||||||
cd build
|
|
||||||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly ..
|
|
||||||
make -j 4 install
|
|
||||||
```
|
|
||||||
* **C compiler errors: headers not found.** Make sure you have 32bit libc installed and visible to your clang.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Contract Interface
|
||||||
|
|
||||||
|
To setup a simple contract one makes use of the `contract` block macro.
|
||||||
|
|
||||||
|
```nim
|
||||||
|
contract("ContractName"):
|
||||||
|
|
||||||
|
proc addition*(a: uint256, b: uint256): string =
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
# Function Visibility
|
||||||
|
|
||||||
|
All nimplay functions need to be annotated as either private or public, all functions marked with
|
||||||
|
and asterisk `*` are public and can be called from a transaction or another contract.
|
||||||
|
If a contract is not marked as public, it will be unreachable from outside the contract.
|
||||||
|
|
||||||
|
# Types
|
||||||
|
|
||||||
|
Type Name | Nim Type | Runtime Size (B) | ABIv1 Size (B)
|
||||||
|
----------|------------- |------------------|---------------
|
||||||
|
uint256 | StUint(256) | 32 | 32
|
||||||
|
address | array[20,byte]| 20 | 32
|
||||||
|
bytes32 | array[32,byte | 32 | 32
|
||||||
|
|
||||||
|
|
||||||
|
# Builtin Variables
|
||||||
|
|
||||||
|
To easily access the current transactions state as well block specific states the following builtin variables are exposed.
|
||||||
|
|
||||||
|
Variable Name | Type | Contents
|
||||||
|
--------------|---------|----------
|
||||||
|
msg.sender | address | Current address making CALL to contract
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Installing
|
||||||
|
|
||||||
|
*Please Note*: Nimplay is still in very early developmental stages, the below lengthy installtion steps will be refined in the future.
|
||||||
|
|
||||||
|
This is a sample of how building eWASM contracts in Nim is possible.
|
||||||
|
Requirements:
|
||||||
|
* clang 7.0 or later with WebAssembly support. Most likely has to be built manually.
|
||||||
|
* 32bit version of libc. On linuxes it is usually provided by the package manager.
|
||||||
|
* `wasm2wat` and `wat2wasm` from [wabt (WebAssembly binary toolkit)](https://github.com/WebAssembly/wabt). They need to be in the `PATH`.
|
||||||
|
* [optional] [wasm-gc](https://github.com/alexcrichton/wasm-gc) optimizer
|
||||||
|
|
||||||
|
## Compiling examples
|
||||||
|
|
||||||
|
```
|
||||||
|
export WASM_LLVM_BIN=/path/to/llvm/bin/folder
|
||||||
|
nimble tools
|
||||||
|
nimble examples
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
* **Emscripten doesn't work!** It is not expected to. Use clang with wasm target enabled.
|
||||||
|
* **clang is difficult to build.** No, it's easy. Follow these steps:
|
||||||
|
|
||||||
|
```
|
||||||
|
tag=release_70
|
||||||
|
INSTALL_PREFIX=$(pwd)/llvm-wasm
|
||||||
|
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/llvm.git
|
||||||
|
cd llvm/tools
|
||||||
|
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/clang
|
||||||
|
git clone --depth 1 --branch $tag https://github.com/llvm-mirror/lld
|
||||||
|
cd ..
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly ..
|
||||||
|
make -j 4 install
|
||||||
|
```
|
||||||
|
|
||||||
|
* **C compiler errors: headers not found.** Make sure you have 32bit libc installed and visible to your clang.
|
Loading…
Reference in New Issue