Hello, I donβt really understand how to use the web3 provider in the ethereum boilerplate.
From what I understood, the ethereum boilerplate has his own context provider, so I should not use
const web3 = await Moralis.enableWeb3();
const contract = new web3.eth.Contract(contractAbi, contractAddress);
So how do I load web3 and the data in the contract ?
I am trying to recreate the following code in the Ethereum Boilerplate with Moralis:
async componentWillMount() {
await this.loadWeb3() await this.loadBlockchainData()
}
async loadWeb3() { if (window.ethereum) { window.web3 = new Web3(window.ethereum) await window.ethereum.enable() } else if (window.web3) { window.web3 = new Web3(window.web3.currentProvider) } else { window.alert('Non-Ethereum browser detected. You should consider trying MetaMask!') }
}
async loadBlockchainData() {
const web3 = window.web3 //Load account const accounts = await web3.eth.getAccounts() this.setState({account: accounts[0]}) const networkData = await TipMyMeme.networks[networkId] if(networkData){ const tipMyMeme = new web3.eth.Contract(TipMyMeme.abi, networkData.address) this.setState({tipMyMeme: tipMyMeme}) const imagesCount = await tipMyMeme.methods.imageCount().call() this.setState({imagesCount}) // Load images for (var i = 1; i <= imagesCount; i++) { const image = await tipMyMeme.methods.images(i).call() this.setState({ images: [...this.state.images, image] }) } // Sort images. Show highest tipped images first this.setState({ images: this.state.images.sort((a,b) => b.tipAmount - a.tipAmount ) }) this.setState({ loading: false}) } else { window.alert("The TipMyMeme contract was not deployed on the network") } this.setState({loading: false})
}