DEV Community

Cover image for Launching the HelloWorld Smart Contract on Litetokens
Marlon Hanks
Marlon Hanks

Posted on

Launching the HelloWorld Smart Contract on Litetokens

Litetokens started as decentralized exchange bootstrapped on the Litecoin Network. At its first genesis, units of XLT emerged within a Pythonic Framework as the direct result of burning 10,000 LTC. The original platform can still be used with a few modifications and as long as enough of the piggyback currency is available. However, unforseen events caused the halting of production of the original Litetokens Framework along with the Tetcoin Family of Cryptocurrencies in 2016.

Alt Text

Four years later, development resumed and the decision was made to abandon the source tree in order to build a new network for XLT. Litetokens is its own independent platform arising as a fork of TRON. Unlike the first version, the new XLT comfortably executes 1000 TPS (Transactions Per Second). That is over a 100X improvement in core performance which makes Litetokens faster than 99.99% of all cryptocurrencies. Naturally, its experiment pipeline is aiming to achieve 10,000 TPS, a subject that goes beyond the scope of this article.

Herein is the knowledge to use and develop the tools required to deploy smart contracts on the Litetokens Network using Microsoft Windows 10. Once the tools are built, it is as simple as point and click to deploy, getting to that point may be challenging individually as the tools are designed for early stage development of Litetokens. The entire process to deploy a smart contract on XLT will change in the future.

Create a Litetokens Development Environment

For developers, a minimum of one computer with windows 10 is currently required for this exercise. End Users interested in just deploying a smart contract and not building the binaries may skip to the section titled "Downloading Binaries".

The Windows 10 PC will need Microsoft Visual Studio 2017 in addition to clang, git, and the Oracle Java 1.8 SDK. Other versions of Visual Studio and Java have not yet been tested. Litetokens executes well within Powershell. Powershell is not required to run the core XLT Platform, however, it is required for Litebox and Liteweb. Both of those packages are for Node.js, which is just better managed on Windows 10 using Powershell. Liteweb is part of the Javascript Framework for Litetokens and is not covered in this article. Refer to the Litetokens Organization on GitHub at https://github.com/litetokens for more information on Litebox. The assumption will be made that these tools are already installed as their installation will not be covered in this article.

Obtain XLT

Litetokens is currently executing an airdrop of XLT. Visit https://dev.to/marlonhanks/how-to-participate-in-the-litetokens-airdrop-75m for details on how to participate as airdrop participation is the only available method of acquiring the XLT needed to complete this exercise. The first round airdrop is distributing 1 Billion XLT with 1 Million XLT going to the first entry. No testnet for Litetokens is currently available.

Build Litetokens Flavored Solidity

Litetokens Studio is a hard fork of Tron Studio. It is believed that no original version existed for Windows and that source tree contains no Windows Binary. The Binary Release of Litetokens Studio is the opposite as no linux binary of Litetokens Solidity is provided due that Litetokens Studio is targeting Windows. Start a Microsoft Visual Studio 2017 Developer Command Prompt, clone the Litetokens Version of Solidity and enter its directory:

git clone https://github.com/litetokens/solidity.git
cd solidity
Enter fullscreen mode Exit fullscreen mode

Build the Compiler:

scripts\install_deps.bat
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..
cmake --build . --config RelWithDebInfo
Enter fullscreen mode Exit fullscreen mode

A new build of solc.exe for Litetokens will be available that may be needed later if your system does not properly deploy the Solidity Compiler.

Build Litetokens Studio

LitetokensStudio is an IDE to develop/deploy/debug smart contract based on LVM. It is available for hacking at https://github.com/litetokens/litetokens-studio and is currently in use by the Litetokens Team. It is at its core a Litetokens Network Client. Clone the the repository and navigate to its location:

git clone https://github.com/litetokens/litetokens-studio.git
cd litetokens-studio
Enter fullscreen mode Exit fullscreen mode

Build the IDE:

.\gradlew.bat build -x test -x check
Enter fullscreen mode Exit fullscreen mode

Create a Default Litetokens Mainnet Configuration File:

notepad build\libs\mainnet.conf
Enter fullscreen mode Exit fullscreen mode

Enter the following as its contents:

net {
  type = mainnet
  # type = testnet
}

storage {
  # Directory for storing persistent data
  db.version = 2,
  db.directory = "/litetokens/database",
  index.directory = "/litetokens/index",

  # This configuration item is only for SolidityNode.
  # Turn off the index is "off", else "on".
  # Turning off the index will significantly improve the performance of the SolidityNode sync block.
  # You can turn off the index if you don't use the two interfaces getTransactionsToThis and getTransactionsFromThis.
  index.switch = "on"

  # This configuration item is used to database write strategy.
  # Synchronous writing is "true", else Asynchronous writing is "false".
  # Asynchronous writing significantly improves the performance of the FullNode sync block.
  # 1. If asynchronous, the write will be flushed from the operating system buffer cache.
  #    the machine crashes, some recent writes may be lost. Note that if it is just the process that
  #    crashes (i.e., the machine does not reboot), no writes will be lost;
  # 2. If synchronous, writes will be flush into leveldb directly.
  #     No writes will be lost when machine crashes, but it is slow.
  db.sync = true,

  # This configuration item controls the transaction result be put into transactionHistory database.
  # Turn off the switch is "off", else "on".
  # Turning off the switch, transaction result will not be put into transactionHistory database;
  # You can turn off the switch if you don't use the interface getransactioninfobyid.
  transHistory.switch = "on",


  # You can custom these 14 databases' configs:

  # account, account-index, asset-issue, block, block-index,
  # block_KDB, peers, properties, recent-block, trans,
  # utxo, votes, witness, witness_schedule.

  # Otherwise, db configs will remain defualt and data will be stored in
  # the path of "output-directory" or which is set by "-d" ("--output-directory").

  # Attention: name is a required field that must be set !!!
  properties = [
//    {
//      name = "account",
//      path = "storage_directory_test",
//      createIfMissing = true,
//      paranoidChecks = true,
//      verifyChecksums = true,
    //      compressionType = 1,        // compressed with snappy
    //      blockSize = 4096,           // 4  KB =         4 * 1024 B
    //      writeBufferSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
    //      cacheSize = 10485760,       // 10 MB = 10 * 1024 * 1024 B
    //      maxOpenFiles = 100
    //    },
//    {
//      name = "account-index",
//      path = "storage_directory_test",
//      createIfMissing = true,
//      paranoidChecks = true,
//      verifyChecksums = true,
    //      compressionType = 1,        // compressed with snappy
    //      blockSize = 4096,           // 4  KB =         4 * 1024 B
    //      writeBufferSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
    //      cacheSize = 10485760,       // 10 MB = 10 * 1024 * 1024 B
    //      maxOpenFiles = 100
    //    },
  ]

}

node.discovery = {
  enable = true
  persist = true
  bind.ip = ""
  external.ip = null
}

node.backup {
  port = 10001
  priority = 8
  members = [
  ]
}

node {
  # trust node for solidity node
  # trustNode = "ip:port"
  trustNode = "149.28.72.3:50051"

  # expose extension api to public or not
  walletExtensionApi = true

  listen.port = 38888

  connection.timeout = 2

  tcpNettyWorkThreadNum = 0

  udpNettyWorkThreadNum = 1

  # Number of validate sign thread, default availableProcessors / 2
  # validateSignThreadNum = 16

  connectFactor = 0.3
  activeConnectFactor = 0.1

  maxActiveNodes = 30

  maxActiveNodesWithSameIp = 2

  minParticipationRate = 15

  # check the peer data transfer ,disconnect factor
  disconnectNumberFactor = 0.4
  maxConnectNumberFactor = 0.8
  receiveTcpMinDataLength = 2048
  isOpenFullTcpDisconnect = true

  p2p {
    version = 1 # 1: mainnet; 100: testnet
  }

  active = [
    # Active establish connection in any case
    # Sample entries:
    # "ip:port",
    # "ip:port"
  ]

  passive = [
    # Passive accept connection in any case
    # Sample entries:
    # "ip:port",
    # "ip:port"
  ]

  http {
    fullNodePort = 8090
    solidityPort = 8091
  }

  rpc {
    port = 50051
    solidityPort = 50061
    # Number of gRPC thread, default availableProcessors / 2
    # thread = 16

    # The maximum number of concurrent calls permitted for each incoming connection
    # maxConcurrentCallsPerConnection =

    # The HTTP/2 flow control window, default 1MB
    # flowControlWindow =

    # Connection being idle for longer than which will be gracefully terminated
    maxConnectionIdleInMillis = 60000

    # Connection lasting longer than which will be gracefully terminated
    # maxConnectionAgeInMillis =

    # The maximum message size allowed to be received on the server, default 4MB
    # maxMessageSize =

    # The maximum size of header list allowed to be received, default 8192
    # maxHeaderListSize =
  }

}



seed.node = {
  # List of the seed nodes
  # Seed nodes are stable full nodes
  # example:
  # ip.list = [
  #   "ip:port",
  #   "ip:port"
  # ]
  ip.list = [
    "149.248.21.40:18888",
    "149.28.72.3:18888"
  ]
}

genesis.block = {
  # Reserve balance
  assets = [
    {
      accountName = "Zion"
      accountType = "AssetIssue"
      address = "LhkLyDg2hWsFRF7Eh3KoAoo7dy5VAgknM2"
      balance = "99000000000000000"
    },
    {
      accountName = "Sun"
      accountType = "AssetIssue"
      address = "LgkN5Q85aZWbej22B2nmH6UHvFDKvBpAhc"
      balance = "0"
    },
    {
      accountName = "Blackhole"
      accountType = "AssetIssue"
      address = "LetuHVRUTGwtaKXZUzaSkwrcm7sYCtbxuD"
      balance = "-9223372036854775808"
    }
  ]

  witnesses = [
    {
      address: "LMVTsSroKEx6RJuqPm9EBFASuCS5D6TXTU",
      url = "https://envoy.litetokens.org",
      voteCount = 700000000
    },
    {
      address: "LMVujiRhZ2G7wmpuJE1UQrshjxYsL7CujU",
      url = "https://envoy.vapory.org",
      voteCount = 200000000
    },
    {
      address: "LeBqMPPTzGCH3Xiq9LqRg6piGFsDFtJs5a",
      url = "https://envoy.xdv.io",
      voteCount = 100000000
    }
  ]

  timestamp = "1620400001000" # Fri, 07 May 2021 15:06:41 GMT
  parentHash = "0x0000000000000000000000000000000000004c697465746f6b656e7320584c54"
}

localwitness = [
  <YOUR CHOSEN PRIVATE KEY>
]

#localwitnesskeystore = [
#  "localwitnesskeystore.json"
#]

block = {
  needSyncCheck = true
  maintenanceTimeInterval = 21600000
  proposalExpireTime = 259200000 // 3 day: 259200000(ms)
}

# Transaction reference block, default is "head", configure to "solid" can avoid TaPos error
xlt.reference.block = "solid" // head;solid;

vm = {
  supportConstant = true
  minTimeRatio = 0.0
  maxTimeRatio = 5.0
  saveInternalTx = true
}

committee = {
  allowCreationOfContracts = 1
}

log.level = {
   root = "INFO" // TRACE;DEBUG;INFO;WARN;ERROR
}
Enter fullscreen mode Exit fullscreen mode

Be sure to replace the entry named '' in the configuration file or starting Litetokens Studio will fail.

Launch Litetokens Studio:

cd build\libs
java -jar LitetokensStudio.jar -c .\mainnet.conf
Enter fullscreen mode Exit fullscreen mode

The IDE will now run and your its window should look like this:

Alt Text

Write the Hello World Contract

One of the downsides to using the studio is that one must wait for it to sync to Litetokens Blockchain. While waiting for the sync it is perfectly fine to edit. Create a HelloWorld.sol by clicking the add document icon on the top left of the windows and the following to its contents:

pragma solidity ^0.4.0;
contract HelloWorld {
  function get()public pure returns (string memory){
    return 'Hello World!';
  }
}
Enter fullscreen mode Exit fullscreen mode

Authenticate the Litetokens Studio Instance

Click on the Profile Button and enter the desired Litetokens Private Key and click the 'ok' button:

Alt Text

For security purposes, we have omitted our private keys from the photos. Litetokens Studio does not save or share your private key with any party.

Compile HelloWorld.sol

Once authenticated, simply click the 'Compile' button. If successful, you will see this popup:

Alt Text

If there is a failure, the studio will inform you in the logs and or its window depending on the type of error. The most common expected error will be a typical null pointer exception. In most cases, the null pointer exception arises from the JVM misreading the location of solc or the improper execution of solc. This is a known bug, which will be addressed as the development of Litetokens Studio progresses. Should you encounter the null pointer bug, follow these steps:

  • Close Litetokens Studio
  • Copy the Solidity Compiler for Litetokens (solc.exe) built earlier to:
c:\users\<your username>\LitetokensStudio\compiler
Enter fullscreen mode Exit fullscreen mode
  • Restart Litetokens Studio

Review ABI and Bytecode

Click on the 'Detail' Button to obtain the ABI and Bytecode:

Alt Text

Run the HelloWorld Smart Contract

After compiling and reviewing the contract, it is time to Deploy it using your private key of choice. Click on the 'Run' tab to set Litetokens Studio to this screen:

Alt Text

Next select your authenticated account from the dropdown list:

Alt Text

Next select which environment to deploy to. In our case, we deploy to the Local LVM and the Mainnet LVM depending on the purpose. Litetokens Studio will now populate information specific to your deployment:

Alt Text

Click on your contract address to copy it

Alt Text

Verify the Deployment

LiteScan [https://litescan.org] is a work in progress. LiteScan XLT block information syncs to both the head and solid entries of the Litetokens Blockchain. At this time is recommended to use the LiteScan API [https://api.litescan.org] to verify transaction records. The LiteScan Frontend does not yet have all Litetokens Features enabled. LiteGrid is still in development at the time of writing this article.

In our case, we deployed to our Local LVM, which points to the Solidified Transaction Reference Block of Litetokens. LiteScan uses the Head Transaction Reference Block to display the latest transactions in realtime:

Alt Text

You should see our Reference Transaction ID of 82096a858698ba7617bc07ce396103e220001a1872ab878ae2e4bbb101b5ac13 in the above list generated by LiteScan.

However, Smart Contracts are not yet fully programmed in the LiteScan Frontend and you will receive an error when selecting the deployed transaction from the list.

To use the LiteScan API to verify your deployment, navigate to https://api.litescan.org and click on the 'GET /api/transaction/{hash} Find transaction by hash' Section:

Alt Text

Next, click on 'Try it out' and enter the Transaction Hash:

Alt Text

Select 'Execute' to query the api in the browser to receive output related to the specific transaction:

Alt Text

Here is the live response for the smart contract we deployed:

{
  "hash": "82096a858698ba7617bc07ce396103e220001a1872ab878ae2e4bbb101b5ac13",
  "block": 103458,
  "timestamp": 1621805117000,
  "confirmed": true,
  "ownerAddress": "",
  "toAddress": "",
  "contractData": {
    "type": "CreateSmartContract"
  },
  "contractType": 30,
  "data": "",
  "fee": 100000000
}
Enter fullscreen mode Exit fullscreen mode

Downloading Binaries

Litetokens Studio Version 1.0.0 includes a 64 Bit Version of Solidity for Litetokens for Windows 10. The debug build provided was created natively using Visual Studio 2017. The Jar file requires Java as no runtime is provided due to licensing. A resolution using the OpenJDK runtime is being explored. The LS Binary may be downloaded at https://github.com/litetokens/litetokens-studio/releases/tag/LS-1.0.0

Conclusion

The information provided here has been done so in the hope that it will be useful. If you have any questions regarding the material of this document, feel free to ask them any time. Thank You for Reading and enjoy Litetokens!

Discussion (0)