0

I want to interact with a simple contract on the ropsten network this is my Js code :

Web3 = require('web3');

if (typeof web3 != 'undefined')
{
    web3 = new Web3(web3.currentProvider);
    console.log("existing web3: provider " + typeof web3);
    console.log(web3.currentProvider);
}
else{
    //To Do..
    web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/"));
    console.log("new provider " + web3);
}

console.log(web3.isConnected());
console.log(web3.eth.accounts[0]);


abi = JSON.parse('[{"constant": false,"inputs": [{"name": "hash","type": "bytes32"}],"name": "apply","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"},{"constant": true,"inputs": [{"name": "email","type": "string"}],"name": "getApplicationID","outputs": [{"name": "","type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"}]');
var ProfContract = web3.eth.contract(abi);
//Ropsten Deployed Address Contract - See Video on Deploying to Ropsten
contractInstance = ProfContract.at('0xcbbfbafedb0eb83016d2a96a4e80d30b20fa3e30');
console.log (contractInstance);

var email = "83b3e70ad37f69ee6cad0255ad8fcdec8b5c42c69dcf7f8273662f7ea6a8fc3c";


function apply() {
console.log("Done: " );

}

But I get this error message on my console

Access to XMLHttpRequest at 'https://ropsten.infura.io/' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.


Uncaught Error: CONNECTION ERROR: Couldn't connect to node https://ropsten.infura.io/.
    at Object.InvalidConnection (errors.js:28)
    at HttpProvider.send (httpprovider.js:76)
    at RequestManager.send (property.js:143)
    at Eth.get [as accounts] (property.js:46)
    at index.js:17
max
  • 5,963
  • 12
  • 49
  • 80

0 Answers0