# Developer Playground Resource

### Note

Binaries were tested on latest version of Ubuntu and Apple Silicon . You may face few hiccups. \
We will ship docker images to make it compatible with cross operating systems.\
For linux system please use binaries stats with `linux-lix` and change commands accordingly.

### Prerequisites

* Setup devbox with required templates
* Clone the repository [https://github.com/L1X-Foundation-Consensus/l1x-examples](https://github.com/L1X-Foundation-Consensus/l1x-examples)
* Repository contains pre-built contracts with the source code
*   Execute following commands to build all contracts.\
    \
    `devbox shell`

    `devbox run compile_all`
* This compiles contracts under **l1x-contracts** folder and produced compiled version with `.o` extension to **l1x-artifacts/**  folder

### Developer playground

* Clone the repository [https://github.com/L1X-Foundation-Consensus/L1X-DEV-PLAYGROUND](https://github.com/L1X-Foundation-Consensus/L1X-DEV-PLAYGROUND)
*   Repository ships with 3 binaries to run a chain locally and to execute contracts

    * l1x\_cli :- CLI to interact with the chain&#x20;
    * l1x\_server :- developer node binary



#### Running a local node

* Please note that this will run an L1X node locally in a developer mode and you will see heaps of info on terminal.
* Make sure  you have setup Cassandra locally
*   Export following environment variables\


    ```bash
    export REPLICATION_ENABLED=false
    export IS_LOCAL=true
    export NODE_PRIVKEY=6913aeae91daf21a8381b1af75272fe6fae8ec4a21110674815c8f0691e32758

    ```
* Initialize the genesis configuration \
  `./l1x_server init`
*   `Run the local node`

    ```bash
    RUST_LOG=info ./l1x_server start
    ```
* This spins up a local node in developer mode

#### Interact with local node using CLI

*   Open a separate terminal and source environment variable(s)

    ```bash
    export PRIV_KEY=6d657bbe6f7604fb53bc22e0b5285d3e2ad17f64441b2dc19b648933850f9b46
    ```


* Execute `./l1x_cli` to view options
* To perform native token transfer execute\
  `./l1x_cli --private-key $PRIV_KEY submit-txn --payload-file-path txn-payload/native_token_transfer.json`\
  \
  You will see the following response&#x20;

\
\
\
`"SubmitTransactionResponse"{ "hash":"7696d4b9005b0ffe1a811751a1d8d18f0addcf2f95d3985caf5c51efb0793a54", "contract_address":"None" }`\


#### Exploring  playground

* Under txn-payload there are several sections&#x20;
  * compiled-contracts
    * Place compiled contracts from example  repository  to corresponding folders or else  you can make your own structure.
* Smart contract deployment
  * For this example we are placing a compiled contract `l1x-contract.o` under `txn-payload\compiled-contracts\l1x-contract`
  *   Find the file **smart\_contract\_deployment.json** and you will see a structure similar to this\
      Change the file attribute to corresponding path \


      ```json
      {
        "smart_contract_deployment": [
          "PRIVATE",
          "L1XVM",
          {
            "file": "txn-payload/compiled_contracts/l1x_contract/l1x_contract.o"
          },
          0,
          {
            "text": "00000000000000000000000000000000"
          }
        ]
      }
      ```
  *   Execute the following command to do a smart contract deployment\


      ```bash
      ./l1x_cli --private-key $PRIV_KEY submit-txn --payload-file-path txn-payload/smart_contract_deployment.json
      ```


  * Now we have deployed our first contract , now we can initialize a contract and invoke its functions&#x20;
  *   To initialize the contract execute\
      Open the file `smart_contract_init.json`\
      Add the contract address from deployment call to `hex` field.\


      ```
      {
        "smart_contract_init": [
          { "hex": "f92286d5f2da5fb627f0b4506d40b0ad98f377c0" },
          { "text": "{}" }
        ]
      }
      ```

      \
      and execute the command&#x20;

      ```bash
      ./l1x_cli --private-key $PRIV_KEY submit-txn --payload-file-path txn-payload/smart_contract_init.json
      ```
  *   Smart contract function call\
      Open the file `smart_contract_function_call.json`\
      \
      Replace contract instance address from `init` call response\
      \


      ```json
      "contract_instance_address": {
        "hex": "beedf108ae904c2adc6700663cf1c850e096094c"
      },
      ```

      \
      Since you already know available functions in the contract you have compiled from examples repository, you can specify  function name  on the text field under function and arguments\
      \


      ```
      {
        "smart_contract_function_call": {
          "contract_instance_address": {
            "hex": "beedf108ae904c2adc6700663cf1c850e096094c"
          },
          "function": {
            "text": "save_event_data"
          },
          "arguments": {
            "text": "{\"global_tx_id\": \"10EC8B28F0F3881BC108B367A9FEED1AA625FBFCBF56F9BC8FA36FDDAAFD5F00\", \"event_type\": \"SwapInitiated\", \"source_id\": \"0\", \"event_data\": \"eyJhZGRyZXNzIjoiMHg3Y2IxM2MyMGIxYzRhZDA4ZjYxNDVjNDJhODZkOWRjMDE5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MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDg2NTc0Njg2NTcyNjU3NTZkMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiYmxvY2tIYXNoIjoiMHhhMGEyNmYzNGJiOGFlMTAxYzhmY2MzNTQ2YTcyMzNkZGFkYjJiZGI2MTljZDUxMTlmNzk3OWI2MWQ5YmUzMTM3IiwiYmxvY2tOdW1iZXIiOiIweDY3ZTgxMmQiLCJ0cmFuc2FjdGlvbkhhc2giOiIweGY3NDEzYWU5MmNlZTBiODQ1ZDFlNTJiODlhYTRkMTRkNTczYWI0NThjMGM4ZjUyYTIzZGE4NTY5OGYzODQwNDIiLCJ0cmFuc2FjdGlvbkluZGV4IjoiMHhhIiwibG9nSW5kZXgiOiIweDI0IiwicmVtb3ZlZCI6ZmFsc2V9\"}"
          }
        }
      }
      ```
* You can explore available json  configuration files for each contracts .&#x20;
* You can change the compiled file paths accordingly&#x20;
* Please refer to the README [https://github.com/L1X-Foundation-Consensus/L1X-DEV-PLAYGROUND#readme](https://github.com/L1X-Foundation-Consensus/L1X-DEV-PLAYGROUND#readme) for complete list of CLI commands (Share the link here)

#### EVM ERC 20 token deployment demo video

{% file src="https://879140870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeTLmER6Ab8VaxeOI6Vla%2Fuploads%2F8k0j8q9njcMtQoAXEV22%2Fevm%20playground.mov?alt=media&token=43ce3201-5362-424a-8f52-beca9a531580" %}

