Setting up the smart contract instance

The first thing that must be done when implementing a smart contract inside a React application is the contract instance so that we can start calling methods from that contract all over the decentralized application. We'll use the compiled contract provided by Truffle and the address of it. Let's perform the following steps:

  1. Import web3 into your project:
import Web3Js from 'web3'

Why do you think I've named the variable Web3Js instead of just Web3? Because MetaMask injects its own version of web3, which is precisely named Web3, so when we develop, we may be used the injected version of web3, instead of the one that we are interested in importing. It's important to use a slightly different name to ...

Get Mastering Ethereum now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.