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

  • 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

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

    export REPLICATION_ENABLED=false
    export IS_LOCAL=true
    export NODE_PRIVKEY=6913aeae91daf21a8381b1af75272fe6fae8ec4a21110674815c8f0691e32758
    
  • Initialize the genesis configuration ./l1x_server init

  • Run the local node

    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)

    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

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

Exploring playground

  • Under txn-payload there are several sections

    • 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

      {
        "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

      ./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

    • 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

      ./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

      "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\": \"eyJhZGRyZXNzIjoiMHg3Y2IxM2MyMGIxYzRhZDA4ZjYxNDVjNDJhODZkOWRjMDE5YjBhMjZlIiwidG9waWNzIjpbIjB4MjAzNGM2N2U0YmM0ZTk5MmI3NGQyZWUyZWQ1NjQ0NGE1MGY5YTJjZmI0NWRjNmZmYWE3MzE1MjA0OWMzYjY0OCIsIjB4MTBlYzhiMjhmMGYzODgxYmMxMDhiMzY3YTlmZWVkMWFhNjI1ZmJmY2JmNTZmOWJjOGZhMzZmZGRhYWZkNWYwMCIsIjB4MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwN2Y1Yzc2NGNiYzE0Zjk2NjliODg4MzdjYTE0OTBjY2ExN2MzMTYwNyJdLCJkYXRhIjoiMHgwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAyNzEwMDAwMDAwMDAwMDAwMDAwMDAw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ZGV4IjoiMHhhIiwibG9nSW5kZXgiOiIweDI0IiwicmVtb3ZlZCI6ZmFsc2V9\"}"
          }
        }
      }
  • You can explore available json configuration files for each contracts .

  • You can change the compiled file paths accordingly

  • Please refer to the 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

Last updated