0

I am trying out my first Solidity project; a todo app. I have worked on the smart contract using remix and tested all its functions, which work as intended. I worked on my frontend and connected it using ethers.js and functions like addTodo, clearAllTasks work perfectly well except the function to get all the tasks.

This is the error I keep getting:

index.js:160 Error fetching todos: Error: call revert exception (method="getTodos()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.2.0)

and this is the code I run to get all the tasks:

async function getTasks() {
  try {
    const todos = await TodoContract.getTodos();
    console.log("Todos:", todos);
    return todos;
  } catch (error) {
    console.error("Error fetching todos:", error);
  }
}

Can someone please help me out?

here is the smart contract

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

contract Todo{

struct TodoItem {
   string  task;
  bool  completed;
}

TodoItem[] public todoList;

function addTodo  (string memory task) public {
   todoList.push(TodoItem(task, false));
}


function getTodos () public view returns(TodoItem[] memory){

return todoList; }

function updateTodo(uint256 index) public  {
    require(index < todoList.length, "index out of range");
    todoList[index].completed = true;
}

function deleteTodo (uint256 index) public {

require(index < todoList.length, "index out of range"); todoList[index] = todoList[todoList.length - 1]; todoList.pop(); }

function clearAll () public {
   delete todoList;
}

function editTodo (uint256 index, string memory updateValue) public {

require(!todoList[index].completed, "todo already completed, set another todo"); todoList[index].task = updateValue; } }

the abi and smart contract address are correct as other parts of the smart contract are interacting properly.

here is a part of my abi

 {
inputs: [],
name: "getTodos",
outputs: [
  {
    components: [
      {
        internalType: "string",
        name: "task",
        type: "string",
      },
      {
        internalType: "bool",
        name: "completed",
        type: "bool",
      },
    ],
    internalType: "struct Todo.TodoItem[]",
    name: "",
    type: "tuple[]",
  },
],
stateMutability: "view",
type: "function",

},

1 Answer 1

0

is there a method named getTodos() in your contract???? please share codes here.

also, maybe you need to add .call() at the end of the const todos = await TodoContract.getTodos();

1
  • hii i just updated the question and i tried to add call(), said call() is not a function
    – Irom Ibe
    Commented Aug 23, 2023 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.