├── .gitattributes ├── Mood_ABI.json ├── README.md ├── contracts └── mood.sol ├── favicon.ico ├── index.html ├── remix_deploy_and_test.png └── test └── index.html /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /Mood_ABI.json: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_mood","type":"string"}],"name":"setMood","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getMood","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}] 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Create An Ethereum Dapp with Ethersjs 2 | 3 | This is a step-by-step tutorial on how to create a front end, deploy a Solidity smart contract, and connect them together. 4 | We will use [Metamask](https://metamask.io), [Remix IDE](https://remix.ethereum.org) and [Ethersjs](https://github.com/ethers-io/ethers.js/). 5 | 6 | By the end of this tutorial you will be able to create a simple HTML front end with buttons that can interact with smart contract functions. The tutorial takes place in 3 stages 7 | 8 | - Create a basic html web page 9 | - Create a basic solidity smart contract 10 | - Connect the web page with the smart contracts using Ethersjs. 11 | 12 | --- 13 | 14 | ### Preparation 15 | 16 | 1. **Download and Install [MetaMask](https://metamask.io)** 17 | - Never used Metamask? Watch [this explainer video](https://youtu.be/wlm4QcA8c4Q?t=66) 18 | 19 | *The important bits for us are: `1:06 to 4:14`* 20 | - Change to the Ropsten Tesnet and get a Copy an account's wallet public address 21 | 22 |
23 | 24 | 25 |
26 | 27 | 28 | 2. **Request some Ropsten Tesnet Ether from a faucet loaded into your Metamask Wallet.** 29 | - [Faucet link to request funds](https://ipfs.io/ipfs/QmVAwVKys271P5EQyEfVSxm7BJDKWt42A2gHvNmxLjZMps/) 30 | - [Blog explaining a faucet and how to use one](https://blog.b9lab.com/when-we-first-built-our-faucet-we-deployed-it-on-the-morden-testnet-70bfbf4e317e) 31 | 32 | 33 | 3. **Install a http server. Use any you like, but we recommend `lite-server` for beginners:** 34 | - Install NPM ([Download and Instructions](https://www.npmjs.com/)) 35 | - Install lite-server (with NPM in a terminal/command prompt): 36 | 37 | ```bash 38 | npm install -g lite-server #install lite-server globally 39 | ``` 40 | --- 41 | 42 | ### Create and Serve a Simple Webpage 43 | 44 | The first step is to create a basic html page. 45 | 46 | 1. Create a new folder (directory) in your terminal using `mkdirHere we can set or get the mood:
63 |137 |
138 |
139 |
140 | ***Be sure to deploy on Ropsten via Remix under the `Injected Web3` environment and confirm the deployment transaction in Metamask***
141 |
142 | Make a new temporary file to hold:
143 | - The deployed contract's address
144 | - Copy it via the copy button next to the deployed contracts pulldown in remix's **Run** tab
145 | - The contract ABI ([what is that?](https://solidity.readthedocs.io/en/develop/abi-spec.html))
146 | - Copy it via the copy button under to the contract in remix's **Compile** tab (also in Details)
147 |
148 | ---
149 |
150 | ### Connect Your Webpage to Your Smart Contract
151 |
152 | Back in your local text editor in `index.html`, add the following code to your html page:
153 |
154 | 1. Import the Ethersjs source into your `index.html` page inside a new set of script tags:
155 |
156 | ```html
157 |
161 |
162 |
19 |
20 |
21 |
22 |
23 |
24 |
26 |
27 | Here we can set or get the mood:
31 |