Intro to Loom Basechain

If you’re a developer looking to build scalable DApps on Ethereum then you’ve probably run into quite a few problems dealing with transaction throughput and cost per transaction.

Enter Loom, a network of sidechains using Delegated Proof of Stake that increases throughput while checkpointing their security using Transfer Gateways to Ethereum mainnet. To learn more about Loom, check out this handy guide.

Basechain is one of the blockchains in the network of Loom blockchains that focuses on providing a robust platform for blockchain games. These chains make use of Transfer Gateways which allow you to transfer assets from the sidechain (in this case, Basechain) to Ethereum mainnet (or any other chain for that matter).

1. Install Loom and Create Your Work Environment

First step to learning something new is just starting to play with it! Let’s go ahead and install the Loom binary on our system, so we can have a local chain to test with. I’m using Linux as my platform, but the steps are basically the same across Linux and Mac. If you’re using Windows, try checking out WSL, but I’ll warn you, it’ll be buggy sometimes. Alternatively, run the chain in a virtual machine or on a remote server for testing, or just go straight to using the testnet — it’s your choice!

$ curl https://raw.githubusercontent.com/loomnetwork/loom-sdk-documentation/master/scripts/get_loom.sh | sh && chmod +x loom

If this command doesn’t work for you (for example, it doesn’t detect that I’m running Arch Linux as the officially tested versions are for debian, ubuntu, and CentOS), then you can alternatively download the latest binary directly using:

$ curl -sL -o loom https://private.delegatecall.com/loom/linux/stable/loom && chmod +x loom

Then we’re going to initialize the genesis file and chaindata directory by running:

$ ./loom init

To start our chain, we can use:

$ ./loom run

By default, the chain runs on port 46657, and we can use the provided block explorer to see the transactions in real time if we so like:

https://blockexplorer.loomx.io/

(If you are not hosting the chain locally, simply change the URL and port number at the bottom to point to the location where you are hosting the chain.) Block generation time is 1 second, so we can have near instant transactions.

One last useful command to note is:

$ ./loom reset

This command will, as it says, reset the chaindata without clearing the config files to give you a fresh chain. Simple run the ./loom run command to start the chain fresh.

2. Generate Keys

To submit transactions to our chain, we’ll also need to create some keys.

$ ./loom genkey -k priv_key -a pub_key

This will create priv_key and pub_key files in your directory containing your keys. Note that it will save your keys in encoded format, and we’ll need access to the raw public key that it outputs, so make sure to save the local address public key output somewhere so we can access it easily later.

3. Sample Code

Let’s create a very simple contract to deploy on our chain. If you don’t have truffle, now would be a good time to get it. Truffle is a framework for creating, testing, and deploying complex solidity applications.

Once you have truffle installed on your machine, let’s clone the example repo from Loom’s GitHub:

$ git clone https://github.com/loomnetwork/truffle-dappchain-example $ cd truffle-dappchain-example

# copy the private key generated earlier to the root directory of the example repo

$ cp ../priv_key extdev_private_key

You can use Yarn to download and install the dependencies.

Let’s take a look at what’s in this repository that’s interesting:

truffle-dappchain-example\

-> extdev_private_key

-> priv_key

-> pub_key

-> truffle_config.js

-> contracts/

The extdev_private_key is the key we generated, and we will use to deploy our code to the testnet. The priv_key and pub_key files in the truffle-dappchain-example directory are the same keys for deploying to a local chain.

truffle_config.js is where we define the different networks we can connect to. Let’s take a look at what’s inside: