so my truffle based application is communicating fine with my smart contracts on my private network, ganache and ganache-cli.
I then deployed it to ropsten where i used the endpoint i got from infura.io as my api-key
Now if i use that same api-key(endpoint) as my httpProvider, everything stops working but if i turn on metamask, it starts working again so i figured it's most likely my connection with ropsten that went wrong.
Here's my script for connecting to ropsten:
import Vue from 'vue'
import App from './App'
import Web3 from 'web3'
import router from './router'
Vue.config.productionTip = false
window.addEventListener('load', function () {
if (typeof web3 !== 'undefined') {
console.log('Web3 injected browser: OK.')
window.web3 = new Web3(window.web3.currentProvider)
} else {
console.log('Web3 injected browser: Fail. You should consider trying MetaMask.')
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
window.web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/<My-API-Key>'));
}
console.log(window.web3.eth.accounts) // returns an empty array, but it's meant to contain the address in that wallet
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
})
Please help me figure out what i'm doing wrong that's making my connection to ropsten not work.
Truffle - 5.0.4
Node - 10.15.0
Web3 - 0.20.6
Windows 10