OK I can’t exactly say where is the problem based on your description but I’ll just write down all the steps here to follow.
- Launch Ganache you will see All the accounts with default balance of 100Eth.
- Go to settings -> Workspace and add your truffle project (point to truffle.js file)
- Open settings -> Server leave the host name as is and you can change the server port to 8545 Press Restart on upper right corner(this is important)
- Once you have server running, open terminal and navigate to your truffle project
- if you have a precompiled contract then do truffle deploy, make sure your contract is displayed as deployed in Ganache.
- After Successful deployment make sure, YOU COPY NEW CONTRACT ADDRESS in to your front end web3, may be you have wrong contract address so check for that.
- Following is my working react code, Hopefully this will help enjoy let me know how it goes.
const web3 = new Web3(Web3.givenProvider);
const contractAddr = ‘0x75fd53D58b707A5F532a1226849d9D8008aaBD30’;
async componentWillMount() {
accounts = await window.ethereum.enable()
flipCoinContractInstance =new web3.eth.Contract(coinFlipAbi, contractAddr, {from : accounts[0]})
}
Also the truffle.js development block
development: {
host: “127.0.0.1”, // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: “*”, // Any network (default: none)
}