遵循tutorial on the truffle website。是否按原样进行了每个步骤和设置。我的truffle compile
和truffle migrate
工作正常。但是当我尝试在松露控制台中执行let instance = await MetaCoin.deployed()
时,出现此错误-
evalmachine.<anonymous>:1
let instance = await MetaCoin.deployed()
^^^^^
Uncaught SyntaxError: await is only valid in async function
答案 0 :(得分:0)
看起来像MetaCoin
的定义没有正确定义
确保您没有在迁移脚本中缺少以下步骤之一
例如:
const MetaCoin = artifacts.require("YourContractFilame")
await deployer.deploy(MetaCoin)
const deployedMetaCoinContract = await MetaCoin.deployed()
答案 1 :(得分:0)
尝试将其放入异步函数中,然后使用.then(),.catch()来查看您的合同是否已部署...
答案 2 :(得分:0)
对于遇到此错误的任何人来说,似乎异步函数被保留为常规函数
module.exports = >async< function(deployer, network, accounts)
因此,由于使用 await 时 async 被排除在外,因此无法与正确的 async 函数配对