Linnia Javascript Library

David Rhodus
Linnia
Published in
4 min readAug 9, 2018

I am excited to announce that Linnia released the Linnia-JS library today. The source code is available at https://github.com/consensys/linnia-js

There is also an NPM package ready for quick install. https://www.npmjs.com/package/@linniaprotocol/linnia-js

From your CLI you can install by running this command:

npm i @linniaprotocol/linnia-js

The Linnia-JS library is basically a SDK that enables developer to get started building Web 3.0 application without having to learn the Solidity programming language.

Its easy to get started using the library. To create the Linnia function you’ll need to pass in a web3 and IPFS provider.

Getting started

Interacting with the linnia requires a connection to the Ethereum network and a storage solution of your choice. If you follow this tutorial, you will be able to use the library to store files in IPFS, a decentralized storage solution that the Linnia team strongly recommends.

Choosing an Ethereum Network to Use

Ethereum is a blockchain-based platform that allows for the operation of decentralized applications. Since the Linnia protocol is still a work in progress, we can test it by either connecting to the Ropsten Ethereum Testnet or use an application called Ganache to simulate an Ethereum network locally. You choose which network to connect to when you pass in the web3 argument to the library constructor, like so:

// local connection, since HttpProvider points to localhost
let web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'))

We strongly recommend starting your development locally with Ganache, then moving to Ropsten when you are ready to go live.

Using Ganache

The other option we have for testing is to simulate an ethereum network locally. Our sister project Truffle has created a great tool called Ganache that allows us to do this. We will use the CLI version.

Our main repository, https://github.com/ConsenSys/Linnia-Smart-Contracts includes a stable version of the CLI and a task to run it

To install it, use:

git clone https://github.com/ConsenSys/Linnia-Smart-Contracts
npm install

Now you can navigate to that repo and run:

npm run start

To run your own simulated blockchain locally on port 7545!

Now, to connect to the local blockchain, create this web3 object and pass it as the first argument to the linnia-js constructor:

// local connection, since HttpProvider points to localhost
let web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'))

Ropsten Testnet

The Ropsten Testnet is a clone of the Ethereum testnet that allows us to deploy and test out our decentralized applications with no risk before deploying them on the Ethereum Mainnet. The Linnia team has already deployed a version of the Linnia Protocol smart contracts on this Testnet, so if you choose to use it, you already have half of the work done for you. On the flip side, all interactions with these contracts are liable to be wiped out at any moment if the Linnia team redeploys.

Registering for an Infura to connect to Ropsten

Infura is a service that allows you to connect to the ethereum network locally without having to run a node. All you need to do to get started with Infura is sign up here.

Once you do, Infura will send you an email with links to use to connect to Infura in this format:

https://ropsten.infura.io/${YOUR_ACCESS_TOKEN}

To connect to Ropsten when using linnia-js, create this web3 object and pass it as the first argument to the linnia-js constructor:

// ropsten connection, since HttpProvider points to authenticated ropsten infura link
let web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/${YOUR_ACCESS_TOKEN}'))

Storing files on IPFS

IPFS, short for InterPlanetary File System, is a peer-to-peer storage solution for files. As with Ethereum, we have the option to either connect to the IPFS network, or run one locally ourselves.

Connecting to IPFS through Infura

If you wish to use Infura to connect to IPFS, congratulations, you are already done!

You can just use the Infura url when connecting, like so:

const IPFS = require('ipfs-api')
const ipfs = new IPFS({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https'
})

To install it locally, head over to the IPFS install page and download the binary. Once done, run:

sudo mv ipfs /usr/local/bin/ipfs

Then, to start the service, run:

ipfs init
ipfs daemon
Come meet the Linnia team

Several members of the Linnia team will be attending the BETHBerlin buildathon as hackers and mentors. We hope to see you there building next generation Web3.0 Dapps.

September 7–9. Berlin. ETHBerlin. Workshops, mini-conf, hackathon, and a radical new experiment for Ethereum community engagement.

--

--