Here is the code of my index.js. I think the problem is here but I spend a week to find the problem and I’m still stuck on this. I hope some of you guys help my with that. I’m following the FullStack video of Syed Muhammad Danish. It’s an application for build a To-Do-List.
require("dotenv").config();
const express = require("express");
const app = express();
const fileUpload = require("express-fileupload");
app.use(
fileUpload({
extended: true,
})
);
app.use(express.static(__dirname));
app.use(express.json());
const path = require("path");
const ethers = require("ethers");
var port = 3000;
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
app.get("/index.html", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
// Connect with the blockchain things
const API_URL = process.env.API_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;
// In order to communicate with the smart contract you have to have de contract address and the ABI
const { abi } = require(`./artifacts/contracts/TaskDoList.sol/TaskDoList.json`);
const provider = new ethers.providers.JsonRpcProvider(API_URL);
const signer = new ethers.Wallet(PRIVATE_KEY, provider);
const contractInstance = new ethers.Contract(CONTRACT_ADDRESS, abi, signer);
app.post("/addTask", async (req, res) => {
var task = req.body.task;
console.log(task);
async function storeDataInBlockchain(task) {
console.log("Adding the task in the blockchain network... ");
const tx = await contractInstance.addTask(task);
await tx.wait();
}
await storeDataInBlockchain(task);
res.send("The task has been registered in the smart contract");
});
app.listen(port, function () {
console.log("App is listening on port 3000");
});
If you want to upload more code, just tell me. Thanks y’all
I tried a lot of things and read a lot of articles about that and somebody told me that is a 403 error. But I don’t know how to fix that.