Deploying Your First App to Loom Basechain: Installing Loom, Setting up Your Environment, and Generating Keys

Dev Bharel
Nov 12, 2018 · 6 min read
Image for post
Image for post


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 | 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 && 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:
(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 $ 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:

-> 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:

Image for post
Image for post

Specifically, if we look at the networks object, we’ll see that there are currently three networks defined.

  1. loom_dapp_chain is defined as the local chain network and used for quickly testing.
  2. extdev_plasma_us1is defined as the plasma chain Loom testnet, and to deploy to that we will need some tokens.
  3. rinkeby is the Rinkeby Ethereum testnet, which we will use later in our Transfer Gateway article.

This is a great template for learning how to add your own networks (for example, a test network on AWS, or maybe add Ropsten as an alternative Ethereum network). If you don’t have an Infura API key for connecting to Ethereum nodes, you can get one here or simply run your own node connecting to whichever node you like.

Finally, in the Contracts folder, you’ll find a series of sample contracts going over how to create ERC20 and ERC721 tokens for Basechain.

This tutorial will only deal with SimpleStore.sol (the others will be covered in our upcoming article). SimpleStore is, as it’s moniker suggests, a simple contract to store and retrieve a value on the blockchain. Nothing fancy, no tokenization, just a barebones contract. This should give you a good hackable contract to supplement with features as you learn.

4. Karma

Note: We have disabled Karma requirements on the testnet.

Just like Ethereum charges gas for deploying smart contracts, deploying smart contracts on Loom blockchains also requires some funding. Paying for deployment of your contracts costs Karma. Unlike Ethereum, however, you don’t have to pay for transactions to and from your contracts. The contract owner would normally pay a monthly fee and all transactions to their contract would be free.

The Basechain testnet is free because it’s intended to be used as a learning and prototyping environment. You only need to provide Karma tokens (which you can get for free from the faucet) and do not have to worry about this monthly fee.

To deploy to your local chain, first make sure your local chain is running by doing:

$ ../loom run

Then in a different terminal let’s first install the dependencies (only need to do this once).

$ npm install

Then we can deploy using Yarn.

$ yarn deploy

By default, yarn deploy will deploy to the loom_dapp_chain network. This network is your local chain and won’t cost any tokens for deployment. You can specify a different network using ‘:’ and a full list of available deploy options are available in the package.json file.

If you try to run the following deployment, you’ll get an error telling you that you don’t have enough Karma tokens. This is because extdev deploys to the Basechain testnet, which, as we mentioned before, requires funding to successfully deploy your code.

$ yarn deploy:extdev

Now if you do:

$ yarn deploy:extdev

Truffle will run through and deploy SimpleStore (along with all other contracts as defined in the migrations) and return to you the addresses they all deployed on. You can interact with these contracts using the endpoint in web3 and treating it like a regular chain.

In the webapp portion of your DApp, simply add:

var extdev = new Web3(';

In our next article, we will cover how to create ERC721 tokens on Basechain and transfer them to Rinkeby Ethereum testnet.

Loom Network is the multichain interop platform for scaling high-performance dapps — already live in production, audited, and battle-tested.

Deploy your dapp to Loom’s Basechain once and reach the widest possible user base across all major blockchains today.

New to Loom? Start here.

Want to stake your LOOM tokens and help secure Basechain? Find out how.

Like what we’re doing here? Stay in the loop by signing up for our private mailing list.

Loom Network

Distributed Enterprise Platform for Healthcare Providers

Thanks to Jacob Frey, 🤖 Robert, and James Martin Duffy

Dev Bharel

Written by

SSI Software Architect @ globaliD

Loom Network

Building a distributed enterprise platform for managing data — focused on healthcare providers and government departments.

Dev Bharel

Written by

SSI Software Architect @ globaliD

Loom Network

Building a distributed enterprise platform for managing data — focused on healthcare providers and government departments.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store