I'm getting this error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8545/. (Reason: CORS request did not succeed).
I'm aware of this GitHub issue: https://github.com/ethereum/web3.js/issues/1802 But my web3 version is 1.2.6. So I think this bug was already fixed, because this GitHub issue is 2 years old.
I'm trying to connect to MetaMask like this:
var web3; if (typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); console.log("web3 was not undefined"); } else { web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); console.log("We are not in the first 'if' statment."); } //long part with ABI EthereumSession.methods.BuyTicket().send({ from: web3.eth.defaultAccount }) .then(receipt => { console.log("We are in the 'then'"); }); This will give error No "from" address specified, if I set an address with web3.eth.defaultAccount = '0x...'; I will get error about Cross-Origin Request
~~This is a simple HTML file with < script> tags, web3 is installed with npm install web3.~~
UPDATE:
(not running as file anymore) Now I'm hosting it in localhost. I removed node_modules folder with web3, now I see the MetaMask injected Web3. This changed some errors, now I need to use different version of EthereumSession.at
Now I'm getting a TypeError: this._eth.sendTransaction is not a function error for this line:
ethereumSessionInstance.BuyTicket({ from: web3.eth.defaultAccount, gas: 100000, value: web3.toWei(0, 'ether') }); BuyTicket() is a Solidity function that has no arguments.
I'm also getting 'Source Map Error' warnings.