call smart contract function web3
import React, { Component } from 'react'
import Web3 from 'web3'
export class App extends Component {
constructor(props) {
super(props)
this.state = {}
}
async componentDidMount() {
const web3 = new Web3("http://localhost:7545")
const accounts = await web3.eth.getAccounts()
this.setState({ account: accounts[0] })
const networkId = await web3.eth.net.getId()
const networkData = require('./abi.json').networks[networkId]
if (networkData) {
const test = new web3.eth.Contract(require('./abi.json').abi, networkData.address)
this.setState({ test })
const sms = await test.methods.appName().call()
return console.log(sms)
}
}
render() {
return (
<div>
<h2>Network</h2>
</div>
)
}
}
export default App