Can't success to fetch listof data in frontend
Closed this issue · 1 comments
ganesh1997oli commented
This is Contract code to return List of TodoItem:
#[ink(message)]
pub fn gettodolist(&self) -> Vec<TodoItem> {
let caller = self.env().caller();
let mut item: Vec<TodoItem> = Vec::new();
for _item in 0..self.item_id {
match self.item.get(_item) {
Some(value) => {
if value.owner == caller {
item.push(value);
}
}
None => (),
}
}
item
}
and on polkadotjs this function return todos as follows:
I use this code to get list of todos in front end. It's response is success but it doesn't return value it gives array 0.
const { gasRequired, result, output } = await contract.query.gettodolist(
address,
{
gasLimit,
storageDepositLimit,
}
);
// const result = await api.call.contractsApi.call(address, contract.address, 0, null, null, msg.toU8a(msg.args.map((_) => account.address)))
// The actual result from RPC as `ContractExecResult`
console.log(result.toHuman());
// the gas consumed for contract execution
console.log(gasRequired.toHuman());
// check if the call was successful
if (result.isOk) {
// output the return value
console.log("This is Success", output?.toHuman());
Can you suggest me anything how to get list of data in Frontend?
bobo-k2 commented
I don't see how this question is related to this repo. This is more StackExchange material, but nevertheless, I don't see anything wrong in your js code. It might be that you are calling different contract from js than one called from Polkadot.js and that contract doesn't have any todo item.