Skip to content

Commit a3424bf

Browse files
committed
Adds tutorial code
0 parents  commit a3424bf

File tree

15 files changed

+22545
-0
lines changed

15 files changed

+22545
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015", "stage-2", "stage-3"]
3+
}

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env
17+
.env.local
18+
.env.development.local
19+
.env.test.local
20+
.env.production.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*

migrations/1_initial_migration.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Migrations = artifacts.require("Migrations");
2+
3+
module.exports = function(deployer) {
4+
deployer.deploy(Migrations);
5+
};

package-lock.json

Lines changed: 22089 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "eth-marketplace",
3+
"version": "0.1.0",
4+
"description": "An Ethereum Marketplace",
5+
"author": "[email protected]",
6+
"dependencies": {
7+
"babel-polyfill": "6.26.0",
8+
"babel-preset-env": "1.7.0",
9+
"babel-preset-es2015": "6.24.1",
10+
"babel-preset-stage-2": "6.24.1",
11+
"babel-preset-stage-3": "6.24.1",
12+
"babel-register": "6.26.0",
13+
"bootstrap": "4.3.1",
14+
"chai": "4.2.0",
15+
"chai-as-promised": "7.1.1",
16+
"chai-bignumber": "3.0.0",
17+
"react": "16.8.4",
18+
"react-bootstrap": "1.0.0-beta.5",
19+
"react-dom": "16.8.4",
20+
"react-scripts": "2.1.3",
21+
"truffle": "5.0.5",
22+
"web3": "1.0.0-beta.55"
23+
},
24+
"scripts": {
25+
"start": "react-scripts start",
26+
"build": "react-scripts build",
27+
"test": "react-scripts test",
28+
"eject": "react-scripts eject"
29+
},
30+
"eslintConfig": {
31+
"extends": "react-app"
32+
},
33+
"browserslist": [
34+
">0.2%",
35+
"not dead",
36+
"not ie <= 11",
37+
"not op_mini all"
38+
]
39+
}

public/favicon.ico

318 KB
Binary file not shown.

public/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
9+
/>
10+
<meta name="theme-color" content="#000000" />
11+
<!--
12+
manifest.json provides metadata used when your web app is installed on a
13+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
14+
-->
15+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
16+
<!--
17+
Notice the use of %PUBLIC_URL% in the tags above.
18+
It will be replaced with the URL of the `public` folder during the build.
19+
Only files inside the `public` folder can be referenced from the HTML.
20+
21+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
22+
work correctly both with client-side routing and a non-root public URL.
23+
Learn how to configure a non-root public URL by running `npm run build`.
24+
-->
25+
<title>Dapp University Starter Kit</title>
26+
</head>
27+
<body>
28+
<noscript>You need to enable JavaScript to run this app.</noscript>
29+
<div id="root"></div>
30+
<!--
31+
This HTML file is a template.
32+
If you open it directly in the browser, you will see an empty page.
33+
34+
You can add webfonts, meta tags, or analytics to this file.
35+
The build step will place the bundled scripts into the <body> tag.
36+
37+
To begin the development, run `npm start` or `yarn start`.
38+
To create a production bundle, use `npm run build` or `yarn build`.
39+
-->
40+
</body>
41+
</html>

public/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "Starter Kit",
3+
"name": "Dapp University Starter Kit",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

src/components/App.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Styles go here */

src/components/App.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import React, { Component } from 'react';
2+
import logo from '../logo.png';
3+
import './App.css';
4+
import Web3 from 'web3'
5+
6+
class App extends Component {
7+
8+
async componentWillMount() {
9+
// Load Web3
10+
let web3 = new Web3('https://mainnet.infura.io/v3/953247d0c42b419aa3416810d625cc8c')
11+
12+
// Fetch latest block
13+
let latestBlock = await web3.eth.getBlock('latest')
14+
console.log('latest block', latestBlock)
15+
this.setState({
16+
blockNumber: latestBlock.number,
17+
difficulty: latestBlock.difficulty
18+
})
19+
20+
// Fetch Gas price
21+
let gasPrice = await web3.eth.getGasPrice()
22+
console.log('gasPrice', gasPrice)
23+
this.setState({
24+
gasPrice: gasPrice
25+
})
26+
27+
// Fetch latest 10 blocks
28+
let block
29+
let latestBlocks = []
30+
for (let i = 0; i < 10; i++) {
31+
block = await web3.eth.getBlock(latestBlock.number - i)
32+
console.log(block)
33+
latestBlocks.push(block)
34+
}
35+
this.setState({
36+
latestBlocks: latestBlocks
37+
})
38+
}
39+
40+
constructor(props) {
41+
super(props)
42+
this.state = {
43+
blockNumber: 0,
44+
difficulty: 0,
45+
gasPrice: 0,
46+
latestBlocks: []
47+
}
48+
}
49+
50+
51+
render() {
52+
return (
53+
<div>
54+
<nav className="navbar navbar-dark fixed-top bg-dark flex-md-nowrap p-0 shadow">
55+
<a
56+
className="navbar-brand col-sm-3 col-md-2 mr-0"
57+
href="http://www.dappuniversity.com/bootcamp"
58+
target="_blank"
59+
rel="noopener noreferrer"
60+
>
61+
Dapp University
62+
</a>
63+
</nav>
64+
<div className="container-fluid mt-5">
65+
<div className="row">
66+
<main role="main" className="col-lg-12 d-flex text-center">
67+
<div className="content mr-auto ml-auto" style={{ width: '800px' }}>
68+
<h5>Ethereum Blockchain Explorer</h5>
69+
<div className="row">
70+
<div className="col-4">
71+
<div className="bg-light pt-4 pb-3 m-1">
72+
<h5>Latest Block</h5>
73+
<p>{this.state.blockNumber}</p>
74+
</div>
75+
</div>
76+
<div className="col-4">
77+
<div className="bg-light pt-4 pb-3 m-1">
78+
<h5>Difficulty</h5>
79+
<p>{this.state.difficulty}</p>
80+
</div>
81+
</div>
82+
<div className="col-4">
83+
<div className="bg-light pt-4 pb-3 m-1">
84+
<h5>Gas Price</h5>
85+
<p>{this.state.gasPrice}</p>
86+
</div>
87+
</div>
88+
89+
</div>
90+
91+
<div className="row">
92+
<div className="col-lg-12 mt-3">
93+
94+
<div className="card">
95+
<div className="card-header">
96+
<h5>Latest Blocks</h5>
97+
</div>
98+
<div className="card-body">
99+
<table className="table">
100+
<thead>
101+
<tr>
102+
<th scope="col">#</th>
103+
<th scope="col">Hash</th>
104+
<th scope="col">Miner</th>
105+
<th scope="col">Timestamp</th>
106+
</tr>
107+
</thead>
108+
<tbody>
109+
{ this.state.latestBlocks.map((block, key) => {
110+
return (
111+
<tr key={key} >
112+
<th scope="row">{block.number}</th>
113+
<td>{block.hash.substring(0,20)}...</td>
114+
<td>{block.miner.substring(0,20)}...</td>
115+
<td>{block.timestamp}</td>
116+
</tr>
117+
)
118+
}) }
119+
</tbody>
120+
</table>
121+
</div>
122+
</div>
123+
124+
</div>
125+
</div>
126+
127+
</div>
128+
</main>
129+
</div>
130+
</div>
131+
</div>
132+
);
133+
}
134+
}
135+
136+
export default App;

0 commit comments

Comments
 (0)