testnet
testnet copied to clipboard
Nim contracts on eWASM
Objective: Develop a detailed pipeline for Contracts in Nim based on the eWASM Specs
People involved: @kggp1995, @AchalaSB and others from eWASM & status.im team
Goal(s):
- Develop a proper emscripten-based transpiler that can convert a
.nim
program (contract) to WASM executable along with other supporting files
Detailed Workflow (Proposed/Expected):
- Writing contracts in Nim as per the eWASM Specs
- Compiling contracts using
emscripten
and generating.wasm
,.js
,.html
& other files. - Generating
.wast
from.wasm
usingwabt
- Getting Hex code for the contracts
- Deploy WASM "Bytecode" & generate new contract address
- Testing wast code in eWASM testnet
- Extending wast file conversion which contains gas usage and metering information
@achalaSB can explain the processes in detail, perhaps?
Also if @lrettig , @axic or someone can confirm the flow's alignment - that'll be great.
I'm sure you are aware of https://github.com/status-im/nim-eth-contracts ? It does some of these steps already.
Yes, but unfortunately it does not support an emscripten-based pipeline, yet.
Why the need for emscripten?
Our perspective was to have the emscripten transpile any LLVM-IR compatible contracts to WASM.
So does that make sense to have a single transpiler that could handle all these languages (c/c++/rust to begin with)? OR would it make sense to allow the clang toolchain take care of it?
Hey, Im working on deploying Nim contract in testnet using Clang
. Facing some issues in unicode.nim
Here's my code
import unittest
import leypa_nim_packagespkg/submodule
proc mains() {.exportwasm.} =
test "correct welcome" : check getWelcomeMessage() == "Hello, World!"
#echo getWelcomeMessage() == "Hello, World!"
Here is my log
nimble test
Executing task test in /home/achala/Codes/kip-gitlab/leypa-nim-packages/leypa_nim_packages.nimble
Verifying dependencies for [email protected]
Compiling /home/achala/Codes/kip-gitlab/leypa-nim-packages/tests/test1.nim (from package leypa_nim_packages) using c backend
Hint: used config file '/home/achala/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf]
Hint: used config file '/home/achala/Codes/kip-gitlab/leypa-nim-packages/tests/config.nims' [Conf]
Hint: system [Processing]
Hint: test1 [Processing]
Hint: unittest [Processing]
Hint: macros [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: bitops [Processing]
Hint: algorithm [Processing]
Hint: unicode [Processing]
../../../../.choosenim/toolchains/nim-0.19.0/lib/pure/unicode.nim(252, 3) Error: type mismatch: got <seq[char]> but expected'string'
Tip: 4 messages have been suppressed, use --verbose to show them.
Error: nimble.nim(1106) nimble
... nimble.nim(1097) doAction
... nimble.nim(1006) test
... nimble.nim(544) execBackend
... tools.nim(28) doCmd
... Execution failed with exit code 1
... Command: "/home/achala/.nimble/bin/nim" c --noNimblePath "-r" "--path:." "/home/achala/Codes/kip-gitlab/leypa-nim-packages/tests/test1.nim"
@AchalaSB , can you describe the pipeline for Nim Contract in detail?
That should help here. TIA!
Here's Detailed workflow of Nim contarcts:
- Writing contracts in Nim as per the eWASM Specs
- Compiling contracts using
clang
and generating.wasm
file i.e usingwasm32-unknown-unknown
(clang >= 6.0) - Generating
.wast
from.wasm
usingwabt
(wasm2wat conversion) - Testing wast code in eWASM testnet & generate new contract address
- Getting Hex code for the contracts
- Getting new wast file which contains gas usage and metering information
@axic I have compiled the Nim contract using emscripten
but the generated wasm
file is not according to the eWASM spec, couldn't deploy in testnet.
How can I get the required wasm
file?
Does it have the proper imports and exports?
You could run wasm-chisel on it to clean some of that up. You need to install it via Rust's cargo: cargo install chisel
.