Build Rapid Ethereum DApp based Clevis

Build Rapid Ethereum DApp based Clevis

By Siham lamssaoui | Ethereum hacks | 30 Dec 2020


 

Clevis is a tool that ease and facilitate rapid dApps prototyping.


It provides a rapid access to different react components and orchestrate smart contracts deployment.

First let's install your local chain:


$ sudo npm install -g ganache-cli; ganache-cli

Then some pre-requisites like nodeJs, geth and MetaMask, use the following commands to install them for Metamask follow this link metamask.io:

$ sudo apt-get update
$ sudo apt-get dist-upgrade -y
$ sudo apt-get upgrade -y
$ sudo apt-get install build-essential python htop -y
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install -y nodejs
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt-get update && sudo apt-get install ethereum -y


You will need to connect your metamask to localhost:8545, which might cause an error "Oops!Something went wrong" and this because your metamask is not connected to geth, run geth that will run an Ethereum full node (may take from hours to days, and requires a few hundred GB of free space), that initialize a local copy of a blank-state EVM, start downloading all blocks in Ethereum history, starting from block 0,and replay all transactions in all blocks in order, updating the state of the EVM with each transaction until it reaches the present day state.

Geth offers three syncmode that you can use, geth --syncmode "full" runs a full node exactly as you’d expect - your machine initializes a local copy of the EVM in its original clean state, downloads every block since the beginning of the blockchain, and executes every transaction in every block, updating the EVM state until it reaches the present-day EVM state, geth --syncmode "fast" downloads all blocks, but also downloads a recent snapshot of the EVM state from a peer (currently the state of the EVM 64 blocks in the past), executing transactions in only the most recent blocks until it reaches the current EVM state. The advantage of "fast" is that it takes much less time to synchronize to the present state; however, it relies on a full archival node peer for a state snapshot, so it isn’t verifying everything for itself, finally, geth --syncmode "light" runs a light node.

Then, run geth in node terminal window using:

$ geth attach [your IPC endpoint path] ## Get it from you terminal while running your node


After you are done with all this setting let's initialize your project with clevis:

$ mkdir testoken
$ cd testoken
$ npx clevis init;npm i ## you will be asked for what directories to use, i personnally used default ones
$ alias clevis='./node_modules/clevis/bin.js
$ clevis version ## make sure everything is running well by getting clevis and web3 version
$ npm start ## this should bring up a webserver to navigate on your frontend http://localhost:3000


Now you you have DApp and an ethereum account ready to be used you can play with it running some tests:


$ clevis send 1 0 @your-address ## send amount to @your-address
$ clevis balance @your-address ## check @your-address balance


Let's create and inject some instructions to smart contract.

$ Clevis create testoken ## create smart contract


pragma solidity ^0.5.0;

contract testoken {

constructor() public {
emit teToken(to,"Contract Created!");
}

function tetoken(string str) public returns (bool){
emit teToken(to,str);
return true;
}

event teToken(uint timestamp, string str);
}


$ clevis compile testoken
$ clevis deploy testoken 0 ## deploy our compiled smart contract to accountindex


Compiling and deploying contract will create a few files of interest, testoken.compiled that can be uploaded to etherscan to verify the source code.

Clevis offers some commands to interact with smart contract:

$ clevis explain testoken ## this command will explain how your contract works
$ clevis contract tetoken testoken 0 "test string" ## this command makes a call to function to your contract and allow you to specify arguments
$ clevis contract eventteToken testoken ## shows all the logs emitted under eventname

 

Now after deploying the contract and make a call to the tetoken function, and create the event with correct string as str now we can test our contract:

$ clevis test testoken

If the test goes well, congrat yourself your contract is well written, compiled, deployed and tested using clevis, now you can inject it to your DApp and start interacting with it from your frontend:

$ clevis test publish


Enjoy learning and hacking on Ethereum.

Follow me for more nice and detailed tutorials. :)

 

 

How do you rate this article?

0


Siham lamssaoui
Siham lamssaoui

Blockchain Developer/ PhD student blockchain security and interoperability


Ethereum hacks
Ethereum hacks

Hack on Ethereum

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.