Bitcoin raised the blockchain technology, where Ethereum took it to the next level. Often said, Blockchin 2.0, Ethereum proved the possibility of blockchain technology beyond financial sector. This public blockchain network is famous for allowing the implementation of smart contracts. Smart Contract acts as a locker where it can be unlocked by certain conditions. Solidity programming language can be used to develop these Smart Contract.
By the end of this article,
- You will have a deployed smart contract in
Ethereumnetwork (Rinkeby Testnet) - You will interact with your smart contract using a react and node app.
Metamask is a pretty neat browser plugin. It allows an end user to interact with a dAPP on ethethreum network. With metamask, end user do not have to run a ethereum node. Metamask also handle users Ethereum Wallet.
- Install Chrome Browser in your machine
- Go to Chrome Web Store and search for
Metamask - Open
Metamaskoffered byhttps://metamask.io/ - Click
Add to Chromeand confirm byAdd Extension - Now
Metamaskshould be available in yourChrome Extensionlist
Using wallet, end users are allowed to send and receive ethers from dApps.
- Open
Metamaskand clickGet Started - If you already have a wallet then go to
Import Wallet - To create a new wallet go for
Create Wallet - Agree with
Privacy Policy, put password and create thewallet - Reveal and save the
Backup Phrasein a secure place - Now go to
Next Section, select the words according to the phrase - Now your wallet is
All Set Up, You should get yourAccount Address
Tesnet like Rinkeby, does not deal with actual money. To deploy and make transaction in ethereum testnet we will require the fake ether.
- Open the
Metamaskplugin - On
top-rightswitch toRinkeby NetworkfromMain Network - Go to
free ether suppliersite. We will follow theirtwitterinstruction. - Go to Twitter and create a
tweetof ourEthereum Account Address- If your
Ethereum Account Addressis0x0000000000000000000000000000000000000000, the just tweet theaddress
- You can include anything with the
address - It is valid, till the
tweetcontains the address.
- If your
- Open the
published tweetin a new page and copy thepage link. - Put the
tweet linkin thefree ether suppliersite and from theGive me ether, select a suitable package - Now in your
Metamask,fake ethershould appear - Sometimes it takes a little more time to
transaction, so wait and also make sure youMetamaskis connected to theRinkebynetwork.
Remix is a online ide to create solidity smart contract. It also has feature to compile, run, deploy and simulate smart contracts.
- Open Remix IDE.
- Select environment
Solidity - Go to
File ExplorerTab and create a fileLottery.sol - Get the Contract Code
- Go to
Solidity CompilerTab and SelectCompiler Versionto0.4.17LanguageasSolidityEVMasCompiler Default
- Now click
Compile Lottery.sol - You can enable
auto-compilebycheckthe checkboxAuto Compile - Go to
Deploy And Run TransactionTab andDeploythe contract in localEVM - Your contract functionality will be available in
Deploy And Run Tracsactiontab, under theDeployed Contractsection
Testnets provide developers a place to kick the smart contract and test before the real assets being involved. These Testnets behave very much like the main-net and does not require actual money(ether). Here we are going to try Rinkeby Testnet.
- Make sure you run the
Lotterycontract using previous section instructions - Open
Metamask, put thepasswordand make sure, you are connected to theRinkebynetwork. - Go to
Deployed And Run Transactiontab and selectEnvironmentisInjected Web3- As account, your
Metamaskwallet address should be selected
- Make sure you have enough
etherin your wallet to deploy the contract - Now click
Deploy. This will deploy yourcontractto theRinkebynetwork. - In the
Remix IDE, checkLog Sectionand grab theTransaction Hashand store it. - Go to Ether Scan and search for the
Transaction Hash. You will get theDeployed Contract Address. Also thisContract Addresswill be required further.
Everything on Ethereum Network is public, including smart contract byte-code. Byte-code is low level stuff and very difficult to understand. You can publish your solidity source code by verify and publish in ether-scan. If you want more people to interact with your smart contract, you should verify and publish your smart-contract.
- From Ether Scan, search the
Transaction HashorContract Addressand go toContract Detailspage - From
Contract Details, go toContracttab - Click
Verify and Publish, and setCompiler TypeasSolidity(Single File)Compiler Versionas0.4.17License TypeasWhatever Your's Requirement
- Click
Continueand putContract CodefromRemix IDEor Gist - Click
Verify and Publishand you should get theContract Byte CodeandContract ABI - Store the
Contract Byte CodeandContract ABIfor future use
This is a react app to interact with our lottery contract.
git clone https://github.com/bmshamsnahid/Decentralized-Lottery-App
To run the react app, please ensure the following environment.
> Make sure `node.js` is installed. To check version, use `node -v`. This is tested in node 10.17.0
>(Optional, only for node.js deployment) In `\config` directory, create file `dev.js` and put local db url with username and password. An example is provide in the same directory named `example-dev.js`
> To use your own contract, update the `/ui/src/contractConfig.js` as your `Contract Address` and `Contract ABI`
To run your app locally, you do not need a server. But for deployment, the static react app should be hosted in node app.
> Install server side dependency by `npm i` in the project-root directory. In case you face any problem, use `yarn` package manager.
> Run server by `npm run dev`
> Server is running in `http://localhost:8080`
> Go to `\ui` and install dependencies `npm i`
> Update `api url` to local node app `http://localhost:8080` in `App.js` file.
> Run the front end `npm start`
> Your app is available in `http://localhost:3000`
> Make sure `metamask` is installed
> Make sure you are connected to `Rinkeby` network and have enough ether
You are all set to go.
It is important to test your smart-contract before deployment.
> To install dependency, Go to root directory and run `npm i`
> Invoke unit-test by `npm run test`
A deployed version of can be found here.
For any query, please leave a response below. I will reply as soon possible. Also, you can contact iXora team for any assistance.
-
TxHash:
0x3349da25727612e32d292b2fd1f1d2ac5d07b35b9b0f62f356f60d3aa65c6241 -
From account:
0x612a306d2707cf0B49A5d76594482f7AfCda506c -
Contract address:
0x8C9815E2372bC6F9Dec915751B31666aB08b2edb
In this article we will simulate a solidity smart contract in remix IDE. Then we will cover test, deployment and interaction for the smart contract. For interaction we will use the node server and react library. Also make sure the we remove read dependency from metamask wallet.
