Add hello and build.sh

This commit is contained in:
Jacques Wagener 2019-05-06 21:25:35 +02:00
parent 9f3f2dc525
commit 3ae1256989
No known key found for this signature in database
GPG Key ID: C294D1025DA0E923
3 changed files with 51 additions and 0 deletions

14
build.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
export WASM_LLVM_BIN="./llvm-wasm/bin/"
function print_contract () {
wasm_file=$1
echo "${wasm_file} eWASM bytecode:"
echo "0x"`xxd -p $wasm_file | tr -d '\n'`
}
nimble examples
if [ $? -eq 0 ]; then
print_contract examples/hello.wasm
fi

View File

@ -15,3 +15,4 @@ proc buildExample(name: string) =
task examples, "Build examples":
buildExample("wrc20")
buildExample("wrc202")
buildExample("hello")

36
examples/hello.nim Normal file
View File

@ -0,0 +1,36 @@
import ../eth_contracts
proc hello(): int64 =
return 1234567
proc main() {.exportwasm.} =
var res: int64 = 1234567
finish(addr res, sizeof(res).int32)
discard """
[
{
"name": "hello",
"outputs": [
{
"type": "int64",
"name": "out"
}
],
"inputs": [
{
"type": "int64",
"name": "a"
},
{
"type": "int64",
"name": "b"
}
],
"constant": false,
"payable": false,
"type": "function",
}
]
"""