did anyone do the simple dapp in 3minutes tutorial on gas prices?, im connected to BSC mainet and connected metamask and everything is working except when i send and recieve real time transactions the Stats wont come up its just displaying empty arrays for user transactions and average gas prices . the transaction history doesnt even display inside metamask . with me send/ receiving bnb transactions
transactions i make are not even displaying in metamask
here is my code :
<!DOCTYPE html>
<html>
<head>
<title> Gas Price Dapp</title>
<!-- Moralis SDK code -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
</head>
<body>
<h1>Gas Stats With Moralis</h1>
<button id="btn-login">Moralis Login</button>
<button id="btn-logout">Logout</button>
<button id="btn-get-stats">Refresh Stats</button>
<script>
const NODE_URL = "https://speedy-nodes-nyc.moralis.io/81333ef42d97c2958c15467c/bsc/mainnet";
const provider = new Web3.providers.HttpProvider(NODE_URL);
const web3 = new Web3(provider);
// connect to Moralis server
Moralis.initialize("vto1JuctQSO3fQGQCx2UjZb6IrqRBYYPQ0VP7pkL");
Moralis.serverURL = "https://rinctnejggwl.bigmoralis.com:2053/server";
// add from here down
async function login() {
let user = Moralis.User.current();
if (!user) {
user = await Moralis.Web3.authenticate();
}
console.log("logged in user:", user);
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
document.getElementById("btn-get-stats").onclick = getStats;
async function getAverageGasPrices() {
const results = await Moralis.Cloud.run("getAvgGas");
console.log("average user gas prices:", results);
}
function getStats() {
const user = Moralis.User.current();
if (user) {
getUserTransactions(user);
}
getAverageGasPrices();
}
async function getUserTransactions(user) {
// create query
const query = new Moralis.Query("EthTransactions");
query.equalTo("from_address", user.get("ethAddress"));
// subscribe to query updates ** add this**
const subscription = await query.subscribe();
handleNewTransaction(subscription);
// run query
const results = await query.find();
console.log("user transactions:", results);
async function handleNewTransaction(subscription) {
// log each new transaction
subscription.on("create", function(data) {
console.log("new transaction: ", data);
});
}
}
// get stats on page load
getStats();
</script>
</body>
</html>