---
# System prepended metadata

title: Learning Deku-parametric

---

# Learning Deku-parametric

## Preparation steps

- Install dependences

```
npm install
```

- Checking the installation:

```
cat package.json
```

- Build project by building `sdk`

folder `deku_js_interop`

```
npm run build
```

This will compile the section 
```
"script":
{
    "build": "tsc src/interop.ts --lib es6 --outDir lib/"
}
```

This we only build the scripts once time.

`deku_js_interop`: is the bridge between Deku and js

## Second steps

Folder `examples`

Create a new folder for the project.

Go into this folder, first step is to initialize the project by using

`npm init`

Then we can start to open the VScode and then in `package.json` we can modify stuff related to the project, for instace: name, version, etc.

## Writing the project in TypeScript (it is Js with type)

### Install TypeScript

```
npm install typescript
```

### Install `sdks` for the project

```
npm install "file:../../sdks/deku_js_interop"
```

`package-lock.json` always commit this file to have a log of dependences. We only commit it if we have modified `package.json` and lead to changing in the `package-lock.json`. 

So now in `package.json` has been compiled

## Start writing the project

### `index.ts`

The `sdks` gives us 3 functions

```
import (main, get, set) from "deku_js_interop"
```

- `main`: register the transition function, init state
- `get`: only get the state from Deku. This always returns a string, we have to pass what `get` gives us. It is a json file.
- `set`: is setting a new value for the state and delete the old state. It is decided by design.

#### Define function

##### Define variables

```
(* the memory address will change *)
let a = ""

(* the memory won't change *)
(* always use this to declare variable *)
const b = ""
```

```
(* define a variable fct with two parameters and the order is mater *)
const fct = (param1, param2) => {
  (* printf *)
  console.log("Hello");
  
}

(*use it*)
fct (1,2)

(* we can give the default number for parameter by *)
const fct = (param1=2, param2=1) =>
...

(*to specify the type using *)

const fct = (param1: string, param2) => ...


(*Declare the record type with two values*)

const value = {
  param1 : 1,
  param2: 2
}

(* calling the other variable*)

const fct2 = (param) => {
  console.log (param.param1),
  console.log(param.param2)
}

(* we can define the interface type for value by using*)

interface value_type {
 param1: number, 
 param2: number,
}

(*using the type interface*)
const fct2 = (param: value_type) =>
{
    const (param1, param2) = param;
    console.log (param1);
    console.log(param2)
}

(*we can unconstruct in the signature directly *)
const fct2 = ({param1, param2}: value_type) => {
console.log(param1);
console.log(param2);
}

(*define a transition function with one parameter, this parameter is a record, we can unconstruct this directly as above example *)

(*these records coming from Deku vm_transaction *)

const transaction = ({sedner, op_hash, tx_hash, operation}) =>
{
    //sender -> is a pb of the one who sent "tz1..."
    
    // op_hash /tx_hash = BLAKE2.t = string
    
    // operation: it is any, it is a payload by the user, it has to be a correct json value, it can be int, string, boolean or an object type
    
    // we have to do a parsing function to have a real type define in our program. Cookie (operation), part each type and handle it. It can not be Null/Undefine.
}


```

##### Register the function

We have the function, the next step is to register it. The reason is to be able to use it. It will call in each Deku transaction function.

```
(* empty record {} is an initial state for the transition function*)
main({
counter:0, 
cookie:"cookie"
}, 
transition)

```

## Actions

### Deku side

Create a wallet

```
deku-cli create-transaction
```

Build `ts` to `js` by using

```
ts index.ts
```

Create a transaction

```
(*build the typescript*)

npm run build

(*this is running without the deku cluster*)
deku-cli create-mock-transaction --help

(*sender payload:empty string path_to_vm: node build ..*)
deku-cli create-mock-transaction tz1...tzsidewallet '""' node index.js
```


### Process on `payload` 

We can access it by the `operation` in `transition`.
It is a string.

### Process with Deku cluster

We need to be at the root folder of Deku.

```
tilt up -- --mode=Local --vm="node examples/marigold-week/index.js"
```








