Skip to content

Instantly share code, notes, and snippets.

@Realkayzee
Created September 3, 2022 19:15
Show Gist options
  • Select an option

  • Save Realkayzee/dd8e96b5bbb24d3a55c73145715a32fa to your computer and use it in GitHub Desktop.

Select an option

Save Realkayzee/dd8e96b5bbb24d3a55c73145715a32fa to your computer and use it in GitHub Desktop.
import getContract from "./utils/getContract.js";
const { ethers: etherjs } = ethers;
async function getTodoList() {
const contract = getContract();
try {
const response = await contract.getTodos();
const formatted = response.map((item) => {
return {
name: item[0],
description: item[1],
status: item[2],
};
});
return formatted;
} catch (error) {
console.log("error", error);
}
}
const upadateTodoUI = async () => {
const data = await getTodoList();
console.log(data, "data");
data.forEach((item) => {
todos.innerHTML += `
<li class='my-2'>${item.description}</li>`;
});
};
upadateTodoUI();
// add new list
async function connectWallet(){
const signerProvider = new etherjs.providers.Web3Provider(window.ethereum);
await signerProvider.send("eth_requestAccounts", []);
}
async function AddTodo(e){
e.preventDefault();
await connectWallet()
const contract = getContract(true);
const mytitle = document.getElementById("title").value;
const mydescription = document.getElementById("description").value;
try {
await contract.createTodo(mytitle, mydescription);
} catch (error) {
console.log("error", error);
}
}
const addButton = document.getElementById("addBtn")
addButton.addEventListener("click", AddTodo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment