首页 > 解决方案 > 为什么我会收到“未捕获的语法错误:意外的保留字”?

问题描述

我正在使用 metamask ethereum API 创建一个网站。但由于某种原因,我在第 8 行收到此错误:
const provider = await detectEthereumProvider();
问题是我直接从 API 网站复制了这段代码,所以我不知道它为什么会收到错误
https://docs.metamask.io/ guide/ethereum-provider.html#using-the-provider
有人可以帮忙吗?谢谢

标签: javascripthtmlethereummetamask

解决方案


await关键字必须在异步函数中调用:

async function main()
{
    // Place your code here.
}
// Then, call that async function that wraps your code:
main();

推荐阅读