A template for Ethereum-based DApp.
components
-- common UI components of a web page such as header, footerethereum
-- ethereum filesbuild
-- compiled contracts<contract-name>.json
-- compiled contract of<contract-name>.sol
contracts
-- solidity contracts<contract-name>.sol
-- solidity file of smart contract
<contract-name>.js
--compile.js
-- compiles<contract-name>.sol
file and generates<contract-name>.json
filedeploy.js
-- deploys the compiled contract onto Blockchain Network (e.g., Rinkeby)factory.js
-- It tells web3 that a deployed copy of the contract exists.web3.js
-- It configures web3 with a Blockchain network provider (in our case it is Rinkeby BC network) from metamask.
pages
-- this directory contains react components that get turned into visitable webpagesindex.js
-- home page of application
test
-- test cases of smart contract<contract-name>.test.js
-- test case of the<contract-name>
package.json
-- project information and list require dependencies for the projectroutes.js
-- list the routes of the projectserver.js
-- boot upnextjs
server and tells to useroutes.js
README.md
-- readme file of the projectnode_modules
-- project dependencies
npm init
to generatepackage.json
filenpm install --save ganache-cli mocha [email protected] fs-extra [email protected]
to install dependenciesnpm install --save [email protected]
for deployment dependenciesnpm install --save [email protected] react react-dom
fornext.js
dependenciesnpm install --save semantic-ui-react
for UI componentsnpm install --save semantic-ui-css
for semantic UI stylesheetnpm install --save next-routes
for routing
- Step 1: write smart contract (
.sol
file) into Remix Editor - Step 2: copy paste the smart contract (
.sol
file) into a file ofcontracts
directory. - Step 3: compile the contract using
compile.js
- Step 4: test the contract using a file of a
test
directory. The contract is deployed on local networkganache
- Step 5: deploy the contract on a test network (e.g., Rinkeby).
- Step 6: extract the address of the deployed contract from console.
- Step 7: Copy the address into
contract-address.txt
file for future use. - Step 8: Create React components into
pages
directory. - Step 9 : configures web3 with a provider from metamask in
web3.js
- Step 10: update
factory.js
file with a deployed contract address (specified incontract-address.txt
) - Step 11: Use factory instance in React components (in
pages
directory) to interact with a deployed contract
Source of images: "Ethereum and Solidity: The Complete Developer's Guide" by Stephen Grider
This is an example of how factory pattern can be used to deploy different instances of a smart contract.
next.js
wrapsreact.js
with some more functionalities such as routing, server-side rendering, hot module reload and so on.
this repository contains React components (as
.js
files) that get turned into visitable webpages. When installed.nextjs
(from.next
folder) starts, it see the react components intopages
directory and turn each into routes (according to its directory path), as shown belowed.
Configure
web3
with a provider from a metamask.
next.js rendering at the server. It renders the pages and sends the HTML code to the browser first, then it sends javascript code to the browser.
It tells that a deployed copy of the contract on Rinkeby network exists
The nextjs server renders the HTML page and sends the HTML pages to the browser.
getInitialProps()
function is executed at nextjs server.