Here's a part of the code:
const Web3 = require('web3');
let web3 = new Web3('http://localhost:8545');
let MyContract = new web3.eth.Contract(abi);
let accounts = await web3.eth.getAccounts();
let contract = await MyContract.deploy({data: code})
.send({from: accounts[0], gas: 1000000});
contract.events.MyEvent((error, result) => {
if (error) {
return console.error(error);
}
}
When I run the code, I get the following error:
Error: No provider set.
at Subscription.subscribe (/node_modules/web3-core-subscriptions/src/subscription.js:199:20)
at Contract._on (/node_modules/web3-eth-contract/src/index.js:634:18)
How can I solve this?