An example e-commerce decentralized application using the Lightstreams Network

Decentralized digital shop example interface

This article showcases a decentralized application that enables people to securely sell & purchase content in a peer-to-peer manner without the need for a central platform or server.

Built with React

The following example uses React for the UI and connects to a configurable Lightstreams Node (either local or remote).

Have a look at the example here: https://example-eshop.lightstreams.io

And the source code is on Github: https://github.com/lightstreams-network/example-eshop

1) Configuring the Lightstreams node provider

The first step is to configure a fully synced node that will be responsible for 1) storing files in the “Smart Vault”, 2) managing accounts, and 3) performing the blockchain calls and transactions.

We highly encourage you to run your own local node, but for the sake of simplicity, you can also connect directly to our public gateway on the Sirius Testnet. The example app itself connects by default to our public gateway.

node configuration

2) Configure Your Account

Create your Lightstreams blockchain account or login using an existing one. The password will be used to encrypt your private key and lock the account keystore file on the node’s disk.

account creation

3) Get some test PHT tokens

For creating a shop, you will need some PHT tokens in order to pay the deploy transaction gas fee. Request them on on community forum.

4) Create a shop

After you configure your account, you will see a dashboard where you can glance at all the shops created by the Lightstreams community members and all the content being sold.

create new eshop

Note: To keep this demo simple, I chose to store the list of metadata (i.e. smart contract addresses) for the shops in a real-time Firebase Database. You could very well store these addresses in another smart contract, IPFS or OrbitDB. I may try to do this in the next version of this demo :-). However, please be aware that the actual data for the shops is stored in a decentralised peer-to-peer manner. As a developer, you will decide how decentralized you want to be when developing your own application. Maybe for your application, it is important that metadata needs to also be stored in a decentralised manner also.

4.1) Under the hood

Creating a shop via the UI will create and deploy a new smart contract on the Lightstreams Testnet, and this Smart Contract will keep track of the digital content you will be selling.

For full documentation about the internals, visit our technical CLI documentation on getting started with e-commerce.

5) Sell/Buy Content

Content for sale is stored in the configured node’s Smart Vault.

For example, why not purchase a picture of a fountain I took in Mallorca for 15 PHTs? Behind the scenes, the Smart Vault will grant the buyer a read permission to access this picture, meanwhile it is securely stored in Lightstreams enhanced & permissioned IPFS storage. When the shop’s Smart Contract receives the funds, it will grant the read access.

PS: Of course, if you attempt to access the IPFS hash QmeTvCCzD9C2tFj46ZoXS4kZWvqZ2ScsY9xHz5w7dLrAMy directly, bypassing the purchasing process, you will get an authorization error! Great, that means it works :)

Conclusion

Thanks to the Lightstreams Network, creating DApps and monetizing commercial content in a decentralized way has just become much easier! If you’d like to build your own shop or application with decentralized shop functionalities, read the Getting started with e-commerce guide.

N.B. Thanks to Andrew Zappella for reading and reviewing this article.

--

--

Lukas Lukac
Lightstreams — The Blockchain for Speed and Privacy

I help developers learn blockchain, program innovative applications and stand out on modern jobs market at https://web3.coach