You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Motoko查询函数时前端出现“Timestamp not found”错误的原因

问题描述

在Dfinity Internet Computer平台使用Motoko开发Web应用时,前端调用查询函数触发未捕获的运行时错误:

Timestamp not found in query response. This suggests a malformed or malicious response.

对应的Motoko查询函数代码:

stable var currentValue: Float = 100;

public query func checkBalance(): async Float {
      return currentValue;
};

前端调用代码(index.js):

import { dbank} from "../../declarations/dbank";

window.addEventListener('load', async () => {
    let currentValue = await dbank.checkBalance();
    document.getElementById("value").innerText = currentValue;
});

错误截图显示上述Timestamp相关错误提示。

解决方案
  • 修正Motoko查询函数的返回类型
    Motoko的query函数属于只读同步调用,无需返回async类型,修改后的代码:
stable var currentValue: Float = 100;

public query func checkBalance(): Float {
      return currentValue;
};
  • 升级dfx到最新稳定版本
    旧版本dfx存在响应格式相关的已知bug,执行以下命令升级:
dfx upgrade
  • 重新部署Canister
    修改代码后重新部署,确保变更生效:
dfx deploy
  • 验证前端代理配置
    本地开发时确保dfx start已启动,前端能通过正确的代理地址访问Canister,避免因代理异常导致的响应格式错误。

内容的提问来源于stack exchange,提问作者Siddharth Saxena

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 19:01:10