Introduction to Loom Network:
Loom Network is a platform to help the Ethereum scale. Loom Network provides a Layer 2 solution that uses Ethereum as it’s the base layer. Using Ethereum as a base layer means base chain assets like ERC20 & ERC721 tokens can have security guarantees of the Ethereum.
The loom is the perfect solution for building scalable applications with almost no transaction cost and very less amount of time for transaction confirmation.
If you don’t know more about the Loom Network and are curious to know, then you can check this handy guide where you can get more ideas about the Loom Network.
Without wasting time, let’s go through the process of deploying smart contracts on the Loom Basechain.
How to Deploy Smart Contract on Loom Chain:
It’s easy to deploy smart contracts on the loom.
Steps to deploy Smart Contract on Loom:
- Integrate Remix with Loom
- Writing your Smart Contract
- Deploy Smart Contract on Loom from Remix IDE.
It’s that simple! Isn’t it?
Step 1: Integrate Remix IDE with Loom
To integrate Remix with loom it requires services that proxies JSON RPC call to Loom. For that, Loom had built a small JSON RPC Proxy. So, here we will install and configure it with the Remix IDE to deploy our smart contract on Loom.
Prerequisites to install JSON RPC Proxy:
- Node.js 10 or higher(recommended v10.15.3)
- Yarn
- Git client
- Clone the JSON RPC Proxy repository:
Open a terminal, cd into your project directory and execute below command:git clone https://github.com/loomnetwork/loom-provider-json-rpc-proxy
- Install Dependencies and Build the Proxy:
For that run below command,cd loom-provider-json-rpc-proxy/ && yarn install && yarn build
- Configure the Proxy:
You need to configure a proxy to connect to Loom Testnet or Loom Basechain. For that, you need to set the following environment variables,PORT: port on which proxy listens for incoming requests. The default port is 8080.
CHAIN_ID: Network Id you want to connect to. default for Mainnet & extdev-plasma-us1 for Testnet. By default, it will connect to Loom Mainnet.
CHAIN_ENDPOINT: the address of the endpoint. The default value is wss://plasma.dappchains.com.Run below command to run proxy against Loom Testnet.PORT=8545 CHAIN_ENDPOINT="wss://extdev-plasma-us1.dappchains.com" CHAIN_ID="extdev-plasma-us1" node .
Run below command to run proxy against Loom Basechain. Make sure deploying smart contracts on Loom Mainnet isn’t free. To deploy a smart contract on Loom Mainnet you need to whitelist your address, which will cost you around 1400 Loom per year ATM.
node .
Step 2: Writing your Smart Contract
Here is our Smart Contract example. It is a very simple smart contract that stores string messages and retrieve it from smart contracts. This is just for demo purposes. You can also use your smart contract code
pragma solidity ^0.4.25; contract HelloWorld { // Define variable message of type string string message; // Write function to change the value of variable message function postMessage(string value) public { message = value; } // Read function to fetch variable message function getMessage() public view returns (string){ return message; } }
Step 3: Deploy Smart Contract on Loom
First of all, we need to configure Remix to use Loom JSON RPC Proxy. For that open Remix Editor. Click on the Run menu and then select the Environment as Web3 Provider.
Now you are good to deploy our solidity Smart Contract to Loom Network. Paste below smart contract code into Remix. Select the appropriate compiler version and compile a smart contract by clicking the Compile button.
After compiling a smart contract you can deploy your smart contract by just clicking the Deploy button.
Conclusion
Cheers. You just deployed your first smart contract code on the Loom network. I hope from now onwards you can deploy smart contracts on the Loom Network. If you have any confusion feel free to comment below.
Stay tuned!