[英]Error - await is only valid in async function, when calling deployed on a truffle smart contract
正在关注松露网站上的教程。 按原样完成每个步骤和设置。 我的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
看起来MetaCoin
的定义未正确定义确保您没有错过迁移脚本中的这些步骤之一,例如:
const MetaCoin = artifacts.require("YourContractFilame")
await deployer.deploy(MetaCoin)
const deployedMetaCoinContract = await MetaCoin.deployed()
尝试将其放入异步 function 中,然后使用.then()、.catch() 来查看您的合约是否已部署...
对于遇到此错误的任何人,它看起来像 async function 被保留为常规 function
module.exports = >async< function(deployer, network, accounts)
因此,由于在使用 await 时忽略了异步,因此无法与正确的异步 function 配对
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.