错误-等待调用仅在松露智能合约上部署的异步功能中有效

时间:2020-05-04 20:01:08

标签: ethereum solidity smartcontracts truffle

遵循tutorial on the truffle website。是否按原样进行了每个步骤和设置。我的truffle compiletruffle migrate工作正常。但是当我尝试在松露控制台中执行let instance = await MetaCoin.deployed()时,出现此错误-

evalmachine.<anonymous>:1
let instance = await MetaCoin.deployed()
               ^^^^^

Uncaught SyntaxError: await is only valid in async function

3 个答案:

答案 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 函数配对