작성
·
254
0
import Web3 from "web3";
import "./app.css";
import ecommerceStoreArtifact from "../../build/contracts/EcommerceStore.json";
var EcommerceStore = contract(ecommerce_store_artifacts);
const App = {
web3: null,
account: null,
start: async function() {
const { web3 } = this;
try {
// get contract instance
const networkId = await web3.eth.net.getId();
const deployedNetwork = ecommerceStoreArtifact.networks[networkId];
this.meta = new web3.eth.Contract(
ecommerceStoreArtifact.abi,
deployedNetwork.address
);
// get accounts
const accounts = await web3.eth.getAccounts();
this.account = accounts[0];
} catch (error) {
console.error("Could not connect to contract or chain.");
}
}
};
window.App = {
start: function() {
var self = this;
//Bootstrap the Metacoin abstraction for use.
EcommerceStore.setProvider(web3.currentProvider);
renderStore();
}
};
function renderStore() {
//get the product count
//loop through and fetch all products by id
var instance;
return EcommerceStore.deployed()
.then(function(f) {
instance = f;
return instance.productIndex.call();
})
.then(function(count) {
for (var i = 1; i <= count; i++) {
renderProduct(instance, i);
}
});
}
function renderProduct(instance, index) {
instance.getProduct.call(index).then(function(f) {
let node = $("<div/>");
console.log(f);
});
}
window.addEventListener("load", function() {
if (window.ethereum) {
// use MetaMask's provider
App.web3 = new Web3(window.ethereum);
window.ethereum.enable(); // get permission to access accounts
} else {
console.warn(
"No web3 detected. Falling back to http://127.0.0.1:9545. You should remove this fallback when you deploy live"
);
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
App.web3 = new Web3(
new Web3.providers.HttpProvider("http://127.0.0.1:9545")
);
}
App.start();
});
index.js 너무 많이 바꼈네요.. ㅜ 이렇게 하면 앞에서 했던 iphoneX 크롬 개발자 도구로 ㅜ쿼리가 되던데 바뀐 index.js 코드에선 안되네요. 뭐가 잘못된 건가요?