You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project was originally a fork of the original [formancehq/numscript](https://github.com/formancehq/numscript) repository, adapted for WASM compatibility while maintaining the core CLI functionality.
3
+
This project is a WebAssembly (WASM) port of the [formancehq/numscript](https://github.com/formancehq/numscript)CLI, enabling you to run Numscript execution in any WASM-compatible environment. Originally forked from the official repository, it now provides a standalone WASM binary that maintains full compatibility with the original CLI functionality.
4
4
5
5
## What is Numscript?
6
6
@@ -17,17 +17,18 @@ You can try Numscript online at [playground.numscript.org](https://playground.nu
You'll need a WebAssembly (WASM) runtime to execute the numscript-wasm binary. This guide uses Wasmtime, but you can also use other WASM runtimes like Wasmer.
26
23
27
-
go build -o numscript-wasm main.go
24
+
**Install Wasmtime:**
25
+
```bash
26
+
curl https://wasmtime.dev/install.sh -sSf | bash
28
27
```
29
28
30
-
This will create a `numscript-wasm` executable in the current directory.
29
+
### Download the Binary
30
+
31
+
Download the WASM binary from the [latest release](https://github.com/PagoPlus/numscript-wasm/releases/latest) for your platform.
31
32
32
33
## Usage
33
34
@@ -38,7 +39,7 @@ The CLI provides two commands: `version` and `run`.
38
39
Display the current version of the CLI:
39
40
40
41
```bash
41
-
./numscript-wasm version
42
+
wasmtime numscript.wasm version
42
43
```
43
44
44
45
**Output:**
@@ -57,15 +58,50 @@ Execute a Numscript with the provided input data. The command reads JSON input f
57
58
58
59
The input JSON must follow this structure:
59
60
60
-
| Field | Type | Description |
61
-
|-------|------|-------------|
62
-
|`script`| string | The Numscript code to execute |
63
-
|`variables`| object |[variables](https://docs.formance.com/numscript/reference/variables) used inside the script. |
|`featureFlags`| object | ❌ | Experimental features to enable (empty objects as values). [Example below](#featureflags)|
68
+
69
+
##### balances
70
+
Is an object containing the account name and their respective assets and balances. Ex:
71
+
```json
72
+
"balances": {
73
+
"foo": {
74
+
"USD/2": 200,
75
+
"EUR/2": 100
76
+
},
77
+
"bar": {
78
+
"BRL/2": 200,
79
+
"JPY/2": 100
80
+
}
81
+
},
82
+
```
83
+
###### Asset Format
84
+
Assets use the format `CURRENCY/PRECISION`:
85
+
-`USD/2` = US Dollars with 2 decimal places
86
+
-`EUR/2` = Euros with 2 decimal places
87
+
-`BTC/8` = Bitcoin with 8 decimal places
88
+
89
+
##### featureFlags
90
+
Is an object containing the name of the feature flag you want to use with an empty object as their value. Ex:
91
+
```json
92
+
"featureFlags": {
93
+
"experimental-oneof": {},
94
+
"experimental-get-amount-function": {},
95
+
"experimental-mid-script-function-call": {}
96
+
}
97
+
```
98
+
99
+
Numscript does not have an official list of feature flags, but you can see the [source code](https://github.com/formancehq/numscript/blob/v0.0.17/internal/flags/flags.go) and the documentation with the [experimental features usage](https://github.com/formancehq/numscript/blob/main/differences-with-machine.md#new-functionalities-feature-flags)
67
100
68
-
#### Complete Example
101
+
#### Examples
102
+
103
+
##### Basic Transfer
104
+
Simple account-to-account transfer:
69
105
70
106
1.**Create an input file** (`example.json`):
71
107
@@ -87,7 +123,7 @@ The input JSON must follow this structure:
87
123
2.**Execute the script**:
88
124
89
125
```bash
90
-
./numscript-wasm run < example.json
126
+
wasmtime numscript.wasm run < example.json
91
127
```
92
128
93
129
3.**Expected output** (JSON format):
@@ -107,10 +143,121 @@ The input JSON must follow this structure:
0 commit comments