Skip to content

Instantly share code, notes, and snippets.

@sajclarke
Created October 1, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajclarke/659c8629924e92f1bc87668c26569c69 to your computer and use it in GitHub Desktop.
Save sajclarke/659c8629924e92f1bc87668c26569c69 to your computer and use it in GitHub Desktop.
Step 1 of polymath tutorial
import React, { Component } from 'react';
import Web3 from 'web3'
import logo from './poly_logo.svg';
import './App.css';
class App extends Component {
constructor(props) {
super(props)
this.state = {
account:null
}
}
componentDidMount = async() => {
try{
const web3 = new Web3(Web3.givenProvider)
const accounts = await web3.eth.getAccounts()
this.setState({account:accounts[0]})
}catch(error){
console.log("Could not connect to web3",error)
}
}
render() {
const {account} = this.state
return (
<div className="App">
<header className="App-header">
<img src={logo} alt="logo" />
<h1 className="App-title">Polymath Tutorial</h1>
</header>
<p className="App-intro">
{(!account)?(
<span>Loading...</span>
):(
<span>Your ETH address is {this.state.account}</span>
)}
</p>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment